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

Segmentation fault when accesing void object of numpy module #10603

Closed
danieltomasz opened this issue Nov 4, 2019 · 9 comments
Closed

Segmentation fault when accesing void object of numpy module #10603

danieltomasz opened this issue Nov 4, 2019 · 9 comments

Comments

@danieltomasz
Copy link

danieltomasz commented Nov 4, 2019

Segmentation fault and Spyder crash when accessing void object of numpy module (loaded from matlab file) in spyder variable explorer

import numpy as np

B = np.load('example.npy', allow_pickle=True )[()]

python 3.6.8
numpy 1.17.3
IPython 7.9.0
I am including example file here
https://www7.zippyshare.com/v/ZvMh1rkg/file.html

@ccordoba12
Copy link
Member

@impact27, could you take a look at this one? It looks like a problem in our comms.

@impact27
Copy link
Contributor

impact27 commented Nov 5, 2019

faulthandler:

Fatal Python error: Segmentation fault

Current thread 0x000000011c26adc0 (most recent call first):
  File "/Users/quentinpeter/Library/Python/3.7/lib/python/site-packages/numpy/core/arrayprint.py", line 1337 in _void_scalar_repr
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/variableexplorer/widgets/collectionsdelegate.py", line 292 in setEditorData
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/variableexplorer/widgets/collectionseditor.py", line 769 in mouseDoubleClickEvent
  File "/Users/quentinpeter/pyscripts/spyder/spyder/app/mainwindow.py", line 3562 in run_spyder
  File "/Users/quentinpeter/pyscripts/spyder/spyder/app/mainwindow.py", line 3663 in main
  File "/Users/quentinpeter/pyscripts/spyder/spyder/app/start.py", line 218 in main
  File "/Applications/Spyder.app/Contents/MacOS/Spyder", line 4 in <module>

Top of c-stack

Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	0x00007fff735ab49a __pthread_kill + 10
1   libsystem_pthread.dylib       	0x00007fff736686cb pthread_kill + 384
2   libsystem_c.dylib             	0x00007fff734c33a2 raise + 26
3   libsystem_platform.dylib      	0x00007fff7365db1d _sigtramp + 29
4   ???                           	000000000000000000 0 + 0
5   _multiarray_umath.cpython-37m-darwin.so	0x0000000104dfb9de PyArray_Item_INCREF + 222
6   _multiarray_umath.cpython-37m-darwin.so	0x0000000104dff4ce PyArray_FromScalar + 206
7   _multiarray_umath.cpython-37m-darwin.so	0x0000000104d34680 PyArray_FromAny + 752
8   _multiarray_umath.cpython-37m-darwin.so	0x0000000104d34c92 PyArray_CheckFromAny + 242
9   _multiarray_umath.cpython-37m-darwin.so	0x0000000104dd74d5 _array_fromobject + 901
10  org.python.python3            	0x0000000103c10d52 _PyMethodDef_RawFastCallKeywords + 722
11  org.python.python3            	0x0000000103c100c9 _PyCFunction_FastCallKeywords + 41
12  org.python.python3            	0x0000000103ce5100 call_function + 656
13  org.python.python3            	0x0000000103ce1c68 _PyEval_EvalFrameDefault + 27416
14  org.python.python3            	0x0000000103c105ad function_code_fastcall + 237
15  org.python.python3            	0x0000000103c11270 _PyObject_CallFunctionVa + 272
16  org.python.python3            	0x0000000103c1142e _PyObject_CallFunction_SizeT + 142
17  org.python.python3            	0x0000000103c4cf0f PyObject_Repr + 127
18  org.python.python3            	0x0000000103c10d87 _PyMethodDef_RawFastCallKeywords + 775
19  org.python.python3            	0x0000000103c100c9 _PyCFunction_FastCallKeywords + 41
20  org.python.python3            	0x0000000103ce5100 call_function + 656
21  org.python.python3            	0x0000000103ce1c68 _PyEval_EvalFrameDefault + 27416
22  org.python.python3            	0x0000000103c105ad function_code_fastcall + 237
23  org.python.python3            	0x0000000103c11053 _PyObject_Call_Prepend + 131
24  org.python.python3            	0x0000000103c101e8 PyObject_Call + 136
25  sip.cpython-37m-darwin.so     	0x000000011395b4c0 sip_api_call_procedure_method + 208
26  QtWidgets.so                  	0x000000011666a26e sipQItemDelegate::setEditorData(QWidget*, QModelIndex const&) const + 206

@impact27
Copy link
Contributor

impact27 commented Nov 5, 2019

Doesn't look like it. Maybe it might be a numpy bug?
It looks like numpy tries to PyArray_Item_INCREF the NULL pointer.

@impact27
Copy link
Contributor

impact27 commented Nov 5, 2019

This is a numpy error. To reproduce:

  1. Open a python interpreter
>>> import numpy as np
>>> import cloudpickle
>>> B = np.load('example.npy', allow_pickle=True )[()]
>>> cloudpickle.dumps(B)
  1. Open a new python interperter
  2. set bin_str to the output of the first interpeter
>>> import cloudpickle
>>> cloudpickle.loads(bin_str)

The process then crashes

The same happens with pickle

@ccordoba12
Copy link
Member

Ok, thanks for digging into this one @impact27! Is there any way to avoid de-serializing this, so we can avoid the crash in our side?

@ccordoba12
Copy link
Member

This is a numpy error

What's the error exactly?

@impact27
Copy link
Contributor

impact27 commented Nov 5, 2019

I can get the same crash with just one interpreter:

import pickle
import numpy as np
B = np.load('example.npy', allow_pickle=True )[()]
data = pickle.dumps(B)
del B
print(pickle.loads(data))

Probably pickle saves a pointer but not the underlying data. The code doesn't crash when de-serializing this, only when trying to access the data (repr(value)).
We could:

  • Disallow the numpy.void datatype ()
  • Do it in another process and expect that this process might crash?

@impact27
Copy link
Contributor

impact27 commented Nov 5, 2019

#10617 should fix this

@ccordoba12 ccordoba12 changed the title segmentation fault when accesing void object of numpy module [Spyder 4.0rc] Segmentation fault when accesing void object of numpy module Nov 5, 2019
@danieltomasz
Copy link
Author

danieltomasz commented Nov 6, 2019

@impact27 I am including (one of) original source mat file, I also included it in the numpy issue;

import scipy.io  as sio
B = sio.loadmat('example.mat')['atlas']
temp = B[0][0]

spyder still crashes when I am trying to access temp variable but I have problem to reproduce pickle behavior

np.save('example', temp)
B = np.load('example.npy', allow_pickle=True )[()]
data = pickle.dumps(B)
del B
print(pickle.loads(data))

gives normal output, but when running as a script in Spyder it gives

An error ocurred while starting the kernel
[IPKernelApp] WARNING | No such comm: 6d37879000a711ea86f2d4258b451ef1
[IPKernelApp] WARNING | No such comm: 6d37879000a711ea86f2d4258b451ef1
[IPKernelApp] WARNING | No such comm: 6d37879000a711ea86f2d4258b451ef1

in the console

@ccordoba12 ccordoba12 modified the milestones: v4.0rc2, v4.0.0, v4.0rc3, 4.1.0 Nov 12, 2019
@goanpeca goanpeca modified the milestones: v4.2.0, Sprint 2 (February) Feb 18, 2020
@ccordoba12 ccordoba12 removed this from the Sprint 02 - II milestone Feb 27, 2020
@ccordoba12 ccordoba12 added v4.2.0 and removed v4.1.0 labels Feb 27, 2020
@ccordoba12 ccordoba12 added this to the v5.1.0 milestone May 15, 2021
@ccordoba12 ccordoba12 removed the v4.2.0 label May 15, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.0.4, v5.1.0 May 24, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.1.0, v5.1.1 Jul 24, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.1.1, v5.1.2 Aug 2, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.1.2, v5.2.0 Aug 11, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.2.0, v5.2.1 Sep 28, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.2.1, v5.2.2 Nov 26, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.2.2, v5.3.0 Dec 19, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.3.0, v5.3.1 Jan 30, 2022
@ccordoba12 ccordoba12 modified the milestones: v5.3.1, v5.3.2 May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants