Skip to content

Commit 2e9b86f

Browse files
authored
Merge pull request #1727 from theairbend3r/master
MicromedIO: Fix integer overflow error
2 parents 361d313 + 37cea06 commit 2e9b86f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

neo/rawio/micromedrawio.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def __init__(self, filename=""):
5151
self.filename = filename
5252

5353
def _parse_header(self):
54-
5554
with open(self.filename, "rb") as fid:
5655
f = StructFile(fid)
5756

@@ -133,7 +132,11 @@ def _parse_header(self):
133132
sig_grounds = []
134133
for c in range(Num_Chan):
135134
zname2, pos, length = zones["LABCOD"]
136-
f.seek(pos + code[c] * 128 + 2, 0)
135+
# Force code[c] which is currently a uint16 (or u2) into a int to prevent integer overflow
136+
# for the following operation -- code[c] * 128 + 2.
137+
# An integer overflow below may have side - effects including but not limited
138+
# to having repeated channel names.
139+
f.seek(pos + int(code[c]) * 128 + 2, 0)
137140

138141
chan_name = f.read(6).strip(b"\x00").decode("ascii")
139142
ground = f.read(6).strip(b"\x00").decode("ascii")
@@ -269,7 +272,6 @@ def _event_count(self, block_index, seg_index, event_channel_index):
269272
return n
270273

271274
def _get_event_timestamps(self, block_index, seg_index, event_channel_index, t_start, t_stop):
272-
273275
raw_event = self._raw_events[event_channel_index][seg_index]
274276

275277
# important : all events timing are related to the first segment t_start

0 commit comments

Comments
 (0)