Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when validating data entries with 0 length #49

Open
fangq opened this issue Sep 15, 2024 · 0 comments
Open

Crash when validating data entries with 0 length #49

fangq opened this issue Sep 15, 2024 · 0 comments

Comments

@fangq
Copy link

fangq commented Sep 15, 2024

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

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

No branches or pull requests

1 participant