Ticket #816 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Constructing numpy.object_ causes a crash

Reported by: pv Owned by: somebody
Priority: normal Milestone: 1.2.0
Component: numpy.core Version: devel
Keywords: crash object_ constructor Cc:

Description

The following code causes a segmentation fault:

import numpy as np
print np.__version__
np.object_(3)

The reason apparently is (see the Valgrind trace below) that the object_ constructor expects a memory address as its parameter. This functionality probably shouldn't be user-visible.

Valgrind trace:

$ valgrind --suppressions=.valgrind/valgrind-python.supp python -c 'import numpy; print numpy.__version__; numpy.object_(3)'
...
1.1.0
==23495== 
==23495== Invalid read of size 4
==23495==    at 0x4A6830F: object_arrtype_new (scalartypes.inc.src:1877)
==23495==    by 0x809EDCC: type_call (typeobject.c:422)
==23495==    by 0x805CB36: PyObject_Call (abstract.c:1861)
==23495==    by 0x80C7986: PyEval_EvalFrameEx (ceval.c:3784)
==23495==    by 0x80CB0D6: PyEval_EvalCodeEx (ceval.c:2836)
==23495==    by 0x80CB226: PyEval_EvalCode (ceval.c:494)
==23495==    by 0x80EB474: PyRun_StringFlags (pythonrun.c:1273)
==23495==    by 0x80EB534: PyRun_SimpleStringFlags (pythonrun.c:900)
==23495==    by 0x8058C80: Py_Main (main.c:512)
==23495==    by 0x80587F1: main (python.c:23)
==23495==  Address 0x3 is not stack'd, malloc'd or (recently) free'd
==23495== 
==23495== Process terminating with default action of signal 11 (SIGSEGV)
==23495==  Access not within mapped region at address 0x3
==23495==    at 0x4A6830F: object_arrtype_new (scalartypes.inc.src:1877)
==23495==    by 0x809EDCC: type_call (typeobject.c:422)
==23495==    by 0x805CB36: PyObject_Call (abstract.c:1861)
==23495==    by 0x80C7986: PyEval_EvalFrameEx (ceval.c:3784)
==23495==    by 0x80CB0D6: PyEval_EvalCodeEx (ceval.c:2836)
==23495==    by 0x80CB226: PyEval_EvalCode (ceval.c:494)
==23495==    by 0x80EB474: PyRun_StringFlags (pythonrun.c:1273)
==23495==    by 0x80EB534: PyRun_SimpleStringFlags (pythonrun.c:900)
==23495==    by 0x8058C80: Py_Main (main.c:512)
==23495==    by 0x80587F1: main (python.c:23)
==23495== 
==23495== ERROR SUMMARY: 34 errors from 9 contexts (suppressed: 1194 from 7)
==23495== malloc/free: in use at exit: 4,800,420 bytes in 4,902 blocks.
==23495== malloc/free: 104,174 allocs, 99,272 frees, 48,061,410 bytes allocated.
==23495== For counts of detected errors, rerun with: -v
==23495== searching for pointers to 4,902 not-freed blocks.
==23495== checked 6,128,912 bytes.
==23495== 
==23495== LEAK SUMMARY:
==23495==    definitely lost: 0 bytes in 0 blocks.
==23495==      possibly lost: 110,244 bytes in 210 blocks.
==23495==    still reachable: 4,690,176 bytes in 4,692 blocks.
==23495==         suppressed: 0 bytes in 0 blocks.
==23495== Rerun with --leak-check=full to see details of leaked memory.
Segmentation fault

Change History

Changed 2 years ago by cdavid

  • status changed from new to closed
  • resolution set to fixed

Fixed in r5688

Changed 2 years ago by chris.burns

  • status changed from closed to reopened
  • resolution fixed deleted

test_for_object_scalar_creation in numpy/core/tests/test_regression.py causes a bus error on OSX (10.5, python 2.5.2).

nosetests -sv test_regression:TestRegression.test_for_object_scalar_creation Ticket #816 ... Bus error

Passing in lists works, scalars do not.

In [1]: import numpy as np

In [2]: np.version Out[2]: '1.2.0.dev5726'

In [3]: c = np.object_([4,5])

In [4]: c Out[4]: array([4, 5], dtype=object)

In [5]: d = np.object_([None, {}, []])

In [6]: d Out[6]: array([None, {}, []], dtype=object)

In [7]: b2 = np.object_(3.0) Bus error cburns@~ 10:27:07 $

These operations also cause a bus error: a = np.object_() b = np.object_(3)

Changed 2 years ago by chris.burns

False alarm. The problem went away with a clean install of the svn trunk.

Changed 2 years ago by chris.burns

  • status changed from reopened to closed
  • resolution set to fixed

Problem was fixed in changeset r5688.

Note: See TracTickets for help on using tickets.