Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] contingency.pyx: Fix out of bound write #2924

Merged

Conversation

ales-erjavec
Copy link
Contributor

@ales-erjavec ales-erjavec commented Feb 26, 2018

Issue

Computing contingencies for more then 127 classes results in an out or bounds write in contingency_floatarray possibly leading to a segmentation fault (in the best case) or just wrong results.

import Orange.statistics.contingency, numpy
X = Orange.data.ContinuousVariable("X")
C = Orange.data.DiscreteVariable("C", values=["C{}".format(i + 1) for i in range(1024)])
domain = Orange.data.Domain([X], [C])
d = Orange.data.Table.from_numpy(
    domain,
    numpy.random.uniform(size=(4000, 1)).round(3),
    numpy.random.randint(0, 1024, size=(4000, 1)),
)
c = Orange.statistics.contingency.get_contingency(d, X, C)

consistently results in a segfault on macOS Python 3.5 due to memory corruption.

Description of changes
  • Enable cython bounds check on contingency_floatarray.
  • Change dtype of classes to intp_t to allow more then 127 'class' values.
Includes
  • Code changes
  • Tests
  • Documentation

Change dtype of classes to intp_t to allow more then 126 'class' values.
Enable cython bounds check.
@codecov-io
Copy link

Codecov Report

Merging #2924 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2924      +/-   ##
==========================================
+ Coverage   82.14%   82.14%   +<.01%     
==========================================
  Files         328      328              
  Lines       56417    56417              
==========================================
+ Hits        46343    46344       +1     
+ Misses      10074    10073       -1

@lanzagar lanzagar added this to the 3.11 milestone Feb 26, 2018
@lanzagar
Copy link
Contributor

Nice catch!

@lanzagar lanzagar merged commit d769f81 into biolab:master Feb 26, 2018
@ales-erjavec ales-erjavec deleted the fixes/contingency-outoff-bounds branch February 26, 2018 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants