Skip to content

Blackrock: fix OverflowError reading .nev files over 4 GiB - #1929

Merged
h-mayorquin merged 3 commits into
NeuralEnsemble:masterfrom
cboulay:nev-over-4gib
Oct 28, 2026
Merged

h-mayorquin merged 3 commits into
NeuralEnsemble:masterfrom
cboulay:nev-over-4gib

Conversation

@cboulay

@cboulay cboulay commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

`_read_nev_data` took `header_size` straight from `self._nev_basic_header["bytes_in_headers"]`, a NumPy `uint32` scalar. Under NumPy 2 (NEP 50), `self._get_file_size(filename) - header_size` then raises `OverflowError: Python integer ... out of bounds for uint32` for any `.nev` over 4 GiB, before the memmap is even created. `_get_nev_rec_times` has the same problem with `bytes_in_data_packets`.

Both values are now cast with `int()`. I checked the other places where header fields meet file sizes or offsets: the NSx paths (2.1, 2.2/3.0 and PTP) already use Python ints, so they are unchanged.

The new test, `test_nev_over_4_gib_does_not_overflow`, needs no data: it stubs a 5 GiB file size and a header with `uint32` fields, mocks `np.memmap`, and checks the `offset` and `shape` passed to it for both methods. It fails with the `OverflowError` above on current master (I checked each of the two fixes on its own) and passes with this change. The Blackrock rawio and io tests pass (32 passed).

This came up with a 4.6 GB spec 2.2 file written by Ripple Trellis. I have not run that file, or any real file over 4 GiB, through this branch; the test is the only check at that size.

bytes_in_headers and bytes_in_data_packets are NumPy uint32 scalars. Under
NumPy 2 (NEP 50), subtracting one from a Python int file size above 2**32
raises OverflowError. Cast to int before doing file-size arithmetic.

@h-mayorquin h-mayorquin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix looks good to me. I ran your test and it fails on master with the OverflowError and passes here.

Can you drop the test. It builds the reader with __new__, sets private attributes and mocks np.memmap, so it depends on the internals of _read_nev_data and _get_nev_rec_times. We did not add tests for the earlier overflow fixes of the same kind either (#1642, #1669, #1690).

@h-mayorquin h-mayorquin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

Thanks for dropping the test.

@h-mayorquin
h-mayorquin merged commit f34f655 into NeuralEnsemble:master Oct 28, 2026
2 of 3 checks passed
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