Loading FIFF would crash with empty raw-data directory - #1003
Conversation
…gracefully fails and that any indices being accessed are valid.
chdinh
left a comment
There was a problem hiding this comment.
Approved as part of the v2.4.0 quality/robustness sweep.
The fix is correct and minimal: FiffStream::setup_read_raw indexed dir[first] without bounds checks, so a malformed FIFF whose raw-data block has an empty (or single-entry) directory would read past the end. Guarding dir.isEmpty() up front and first < dir.size() on the DATA_SKIP access resolves it. All CI is green.
Follow-up (I will push a small hardening commit to staging): the same routine derives per-buffer sample counts via ent->size / (k * nchan), which divides by zero if a malformed measurement info reports 0 channels. I'll add an nchan <= 0 guard alongside a regression test in test_fiff_raw_io covering the empty-directory case. Thanks @ag-fieldline for catching the original crash.
Follow-up to #1003. Besides the empty-directory guard, reject a measurement info reporting zero channels up front: the per-buffer sample count divides the data-buffer size by the channel count, so nchan == 0 would divide by zero. Add a regression test in test_fiff_raw_io that writes a raw FIFF with an empty data directory and asserts it fails gracefully instead of crashing.
Loading FIFF would crash with empty raw-data directory. Make sure it gracefully fails and that any indices being accessed are valid.