hdf5 icon indicating copy to clipboard operation
hdf5 copied to clipboard

Segmentation fault when opening unseekable file

Open kalvdans opened this issue 3 years ago • 1 comments

I tried to use /dev/null in a unit test (since I'm not interested in the result) but the library crashes hard. This is a minimal test case:

#include <H5Fpublic.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    hid_t fileobject = H5Fcreate("/dev/null", H5F_ACC_TRUNC, 0, 0);
    return H5Fclose(fileobject);
}

The output when running is:

$ gcc -Wall h5py-bug-1775.c -I /usr/include/hdf5/serial -l hdf5_serial && ./a.out 
HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 139699578592128:
  #000: ../../../src/H5F.c line 668 in H5Fclose(): closing file ID failed
    major: File accessibilty
    minor: Unable to close file
  #001: ../../../src/H5Fint.c line 2047 in H5F__close(): decrementing file ID failed
    major: File accessibilty
    minor: Unable to decrement reference count
  #002: ../../../src/H5I.c line 1309 in H5I_dec_app_ref(): can't decrement ID ref count
    major: Object atom
    minor: Unable to decrement reference count
  #003: ../../../src/H5Fint.c line 2105 in H5F__close_cb(): can't close file
    major: File accessibilty
    minor: Unable to close file
  #004: ../../../src/H5Fint.c line 2276 in H5F_try_close(): problems closing file
    major: File accessibilty
    minor: Unable to close file
  #005: ../../../src/H5Fint.c line 1130 in H5F__dest(): unable to flush cached data (phase 2)
    major: File accessibilty
    minor: Unable to flush data from cache
  #006: ../../../src/H5Fint.c line 1896 in H5F__flush_phase2(): low level truncate failed
    major: File accessibilty
    minor: Write failed
  #007: ../../../src/H5FD.c line 1581 in H5FD_truncate(): driver truncate request failed
    major: Virtual File Layer
    minor: Can't update object
  #008: ../../../src/H5FDsec2.c line 892 in H5FD_sec2_truncate(): unable to extend file properly, errno = 22, error message = 'Invalid argument'
    major: Low-level I/O
    minor: Seek failed
Segmentation fault

I understand that hdf5 library wants to seek in the file, but it should fail gracefully. My version:

$ dpkg -l | grep libhdf5-dev
ii  libhdf5-dev                                   1.10.4+repack-11ubuntu1                                         amd64        Hierarchical Data Format 5 (HDF5) - development files - serial version

kalvdans avatar Mar 13 '22 19:03 kalvdans

For something that looks like a simple fix, addressing this is probably going to involve tidying a rat's nest of file cleanup code.

For the record, the "/dev/nul" equivalent on Windows is "NUL"

derobins avatar May 26 '22 01:05 derobins