Skip to content

Crash when validating data entries with 0 length #49

Description

@fangq

when validating the minimum_example.snirf sample file in the snirf-samples repo, the validator crashed with the following error

Python 3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 15:12:24) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snirf import validateSnirf
>>> import os
>>> os.chdir('snirf-samples/test')
>>> 
>>> result = validateSnirf(r'minimum_example.snirf')
2
<HDF5 dataset "sourceIndex": shape (0, 0), type "<i4">
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 6288, in validateSnirf
    with Snirf(path, 'r') as snirf:
         ^^^^^^^^^^^^^^^^
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 5797, in __init__
    self.nirs = Nirs(self, self._cfg)  # Indexed group
                ^^^^^^^^^^^^^^^^^^^^^
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 3708, in __init__
    super().__init__(h, cfg)
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 1085, in __init__
    self._populate_list()
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 1261, in _populate_list
    self._element(self._parent._h[name].id, self._cfg))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 3444, in __init__
    self.data = Data(self, self._cfg)  # Indexed group
                ^^^^^^^^^^^^^^^^^^^^^
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 3974, in __init__
    super().__init__(h, cfg)
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 1085, in __init__
    self._populate_list()
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 1261, in _populate_list
    self._element(self._parent._h[name].id, self._cfg))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 3740, in __init__
    self.measurementList = MeasurementList(self,
                           ^^^^^^^^^^^^^^^^^^^^^
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 5049, in __init__
    super().__init__(h, cfg)
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 1085, in __init__
    self._populate_list()
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 1261, in _populate_list
    self._element(self._parent._h[name].id, self._cfg))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 4015, in __init__
    self._sourceIndex = _read_int(self._h['sourceIndex'])
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Temp/pysnirf2/snirf/pysnirf2.py", line 394, in _read_int
    return int(dataset[0])
               ~~~~~~~^^^
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "/home/fangq/.local/lib/python3.12/site-packages/h5py/_hl/dataset.py", line 758, in __getitem__
    return self._fast_reader.read(args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "h5py/_selector.pyx", line 361, in h5py._selector.Reader.read
  File "h5py/_selector.pyx", line 151, in h5py._selector.Selector.apply_args
IndexError: Index (0) out of range for empty dimension

it seems that the validator assumes the data item must be non-empty - but our specification does not require the data item must be non-empty.

I think this is a bug in the validator and should permit length-0 entries.

once fix this, I believe snirf-samples should be ready to add new data examples, see fNIRS/snirf#156

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions