Skip to content

Loading FIFF would crash with empty raw-data directory - #1003

Merged
chdinh merged 1 commit into
mne-tools:stagingfrom
ag-fieldline:malformed-fif-empty-directory-crash
Jul 11, 2026
Merged

Loading FIFF would crash with empty raw-data directory#1003
chdinh merged 1 commit into
mne-tools:stagingfrom
ag-fieldline:malformed-fif-empty-directory-crash

Conversation

@ag-fieldline

Copy link
Copy Markdown
Contributor

Loading FIFF would crash with empty raw-data directory. Make sure it gracefully fails and that any indices being accessed are valid.

…gracefully fails and that any indices being accessed are valid.

@chdinh chdinh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chdinh
chdinh merged commit 114fdab into mne-tools:staging Jul 11, 2026
11 checks passed
chdinh added a commit that referenced this pull request Jul 11, 2026
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.
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

Successfully merging this pull request may close these issues.

2 participants