From d4c74b9f1d0d5db9b73dbdace837c06cac22d6dd Mon Sep 17 00:00:00 2001 From: hatute Date: Wed, 18 Sep 2024 00:15:42 -0400 Subject: [PATCH] [fix] edf.py: potential overflow with n_events=256 since the n_events assigned with the UINT8 type of number "ne". So, the default type of n_events will also be UINT8. During the summation of all three byte of "ne" will potentially cause overflow. In my case, python raised overflow error when it reach 256 which exceed the upper limit of 255. Direct Bit-Wise operation can avoid this. --- mne/io/edf/edf.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mne/io/edf/edf.py b/mne/io/edf/edf.py index 778102c28b4..04e070f3670 100644 --- a/mne/io/edf/edf.py +++ b/mne/io/edf/edf.py @@ -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) event_sr = np.fromfile(fid, FLOAT32, 1)[0] pos = np.fromfile(fid, UINT32, n_events) - 1 # 1-based inds