Skip to content

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Apr 8, 2021

Fix #939: a segfault (triggered reproducibly with pip builds) with legacy libSplash HDF5 files.
Introduced in #641 (0.10.3-alpha and newer).

From the docs:

Name: H5Tget_member_name
  ...
  The HDF5 Library allocates a buffer to receive the name of the
  field. The caller must subsequently free the buffer with
  H5free_memory.

I did not need this in my test to fix the segfault, but revisiting the logic I also noticed that passing nullptrs to str(n)cmp is undefined behavior and fixed that as well.

Refs.:

Fix a segfault (on some systems) with legacy libSplash HDF5 files.

From the docs:
```
Name: H5Tget_member_name
  ...
  The HDF5 Library allocates a buffer to receive the name of the
  field. The caller must subsequently free the buffer with
  H5free_memory.
```
Refs.:
- https://support.hdfgroup.org/HDF5/doc/RM/RM_H5T.html#Datatype-GetMemberName
- https://support.hdfgroup.org/HDF5/doc/RM/RM_H5.html#Library-FreeMemory
Passing potential `nullptr`s is undefined behavior.
@ax3l ax3l merged commit f5dc8e2 into openPMD:dev Apr 9, 2021
@ax3l ax3l deleted the fix-segfaultHDF5FreeLibSplashNameType branch April 9, 2021 00:47
ax3l added a commit to ax3l/openPMD-api that referenced this pull request Apr 9, 2021
* HDF5: Fix Segfault with libSplash Files

Fix a segfault (on some systems) with legacy libSplash HDF5 files.

From the docs:
```
Name: H5Tget_member_name
  ...
  The HDF5 Library allocates a buffer to receive the name of the
  field. The caller must subsequently free the buffer with
  H5free_memory.
```
Refs.:
- https://support.hdfgroup.org/HDF5/doc/RM/RM_H5T.html#Datatype-GetMemberName
- https://support.hdfgroup.org/HDF5/doc/RM/RM_H5.html#Library-FreeMemory

* avoid undefined behavior in str(n)cmp

Passing potential `nullptr`s is undefined behavior.

* Clang-Tidy: Intentional Branch Clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segfault when reading libSplash file

2 participants