#22 HDF5 crash opening non-writable files.

closed
nobody
None
5
2005-04-26
2005-02-24
No

PyTables 0.9.1 crashes when opening in 'a' or 'r+' mode
an HDF5 file which can not be modified:

`crash.py`::
import tables, os

h5f = tables.openFile('t.h5', 'w')
h5f.close()

os.chmod('t.h5', 0444) # r--r--r--

# This does not crash.
h5f = tables.openFile('t.h5', 'r')
h5f.close()

# This crashes.
h5f = tables.openFile('t.h5', 'a')
h5f.close()

# This crashes:
h5f = tables.openFile('t.h5', 'r+')
h5f.close()

This is the output (up to the first crash)::

HDF5-DIAG: Error detected in HDF5 library version:
1.6.2 thread -1209605376. Back trace follows.
#000: ../../../src/H5F.c line 2408 in H5Fopen():
unable to open file
major(04): File interface
minor(15): Unable to open file
#001: ../../../src/H5F.c line 1843 in H5F_open():
unable to open file
major(04): File interface
minor(15): Unable to open file
#002: ../../../src/H5FD.c line 968 in
H5FD_open(): open failed
major(22): Virtual File Layer
minor(27): Unable to initialize object
#003: ../../../src/H5FDsec2.c line 321 in
H5FD_sec2_open(): unable to open file
major(04): File interface
minor(15): Unable to open file
HDF5-DIAG: Error detected in HDF5 library version:
1.6.2 thread -1209605376. Back trace follows.
#000: ../../../src/H5G.c line 290 in H5Gopen():
not a location
major(01): Function arguments
minor(03): Inappropriate type
#001: ../../../src/H5G.c line 2305 in H5G_loc():
invalid object ID
major(01): Function arguments
minor(05): Bad value
Traceback (most recent call last):
File "crash.py", line 11, in ?
h5f = tables.openFile('t.h5', 'a')
File
"/home/ivan/_/programari/pytables/pytables-0.9/tables/File.py",
line 226, in openFile
return File(path, mode, title, new, trMap,
rootUEP, isPTFile, filters)
File
"/home/ivan/_/programari/pytables/pytables-0.9/tables/File.py",
line 313, in __init__
self.root = self.__getRootGroup(rootUEP)
File
"/home/ivan/_/programari/pytables/pytables-0.9/tables/File.py",
line 373, in __getRootGroup
newattr["_v_objectID"] = rootGroup._g_openGroup()
File "hdf5Extension.pyx", line 1419, in
hdf5Extension.Group._g_openGroup
RuntimeError: Can't open the group: '/'.

The offending HDF5 function is H5Gopen. The condition
should be caught before calling the function by testing
file permissions, and an IOError should be raised.

Discussion

  • Logged In: YES
    user_id=1064183

    These cases are now caught *before* using the HDF5
    functions, and an ``IOError`` is raised. For instance, the
    previous code shows the following output::

    Traceback (most recent call last):
    File "crash.py", line 9, in ?
    h5f = tables.openFile('t.h5', 'r')
    File
    "/home/ivan/_/programari/pytables/pytables/tables/File.py",
    line 211, in openFile
    checkFileAccess(path, mode)
    File
    "/home/ivan/_/programari/pytables/pytables/tables/utils.py",
    line 335, in checkFileAccess
    raise IOError("file ``%s`` exists but it can not be read"
    IOError: file ``t.h5`` exists but it can not be read

    The update is available at the daily snapshots.

     
    • status: open --> closed