Skip to content

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
shahramn added a commit that referenced this pull request Mar 11, 2025
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