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

#30: Fix segfault from invalid pointer reference in grib_set_double_array() #31

Merged
merged 2 commits into from
Jul 28, 2020

Conversation

direvus
Copy link

@direvus direvus commented Jul 28, 2020

This PR aims to fix a problem in grib_set_double_array() which can lead to a segfault against numpy versions from 1.17.4 onwards.

The segfault seems to occur due to using a numpy array's ctypes.data as the target for an ffi.cast, and then immediately overwriting the numpy array with the results of the cast.

The fix is simply to avoid overwriting the numpy array altogether, and keep the FFI ctype object in its own variable.

Brendan Jurd added 2 commits July 28, 2020 20:47
This is to work around a bug when eccodes is used with numpy >= 1.17.4.
Overwriting an existing numpy array variable with a FFI ctype object causes
invalid pointer derefs, which results in a variety of bad outcomes, ranging
from segfaults to invalid data.

The workaround is simply to use a separate working variable to hold the numpy
array in grib_set_double_array(), and avoid overwriting it with the ctype
object.  The workaround has been tested against the following numpy versions:
- 1.17.3
- 1.17.4
- 1.17.5
- 1.18.0
- 1.19.0
@shahramn
Copy link
Collaborator

Thank you for your contribution

@shahramn shahramn merged commit cd14fdc into ecmwf:develop Jul 28, 2020
@direvus direvus deleted the bugfix/overwrite-np-array branch July 28, 2020 23:45
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.

2 participants