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

[fix] edf.py: potential overflow with n_events=256 #12859

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions mne/io/edf/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,9 +1440,7 @@ def _read_gdf_header(fname, exclude, include=None):
n_events = np.fromfile(fid, UINT32, 1)[0]
else:
ne = np.fromfile(fid, UINT8, 3)
n_events = ne[0]
for i in range(1, len(ne)):
n_events = n_events + ne[i] * 2 ** (i * 8)
n_events = ne[0] + (ne[1] << 8) + (ne[2] << 16)
Comment on lines 1442 to +1443
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a fix on NumPy < 2 but on 2.1 I get:

>>> np.uint8(255) + np.uint8(255)
<stdin>:1: RuntimeWarning: overflow encountered in scalar add
np.uint8(254)

So I think maybe doing this would be a clean way to fix it

ne = np.fromfile(fid, UINT8, 3).astype(np.int64)

or similar

event_sr = np.fromfile(fid, FLOAT32, 1)[0]

pos = np.fromfile(fid, UINT32, n_events) - 1 # 1-based inds
Expand Down
Loading