Skip to content

Commit

Permalink
check length ensure msg is good for unpack
Browse files Browse the repository at this point in the history
  • Loading branch information
nlpng committed Oct 10, 2024
1 parent f9e5602 commit 9fc089b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ def main():

data = msg[0]
timestamp = msg[1]

if len(data) < 6:
# somehow data that is not enough to unpack
# the class, id, and payload length
continue

if data[0] == SYNC1 and data[1] == SYNC2:
try:
(cls, id, payload_len) = struct.unpack("<BBH", bytes(data[2:6]))
Expand Down
6 changes: 6 additions & 0 deletions main_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def parsing(self):

data = msg[0]
timestamp = msg[1]

if len(data) < 6:
# somehow data that is not enough to unpack
# the class, id, and payload length
continue

if data[0] == SYNC1 and data[1] == SYNC2:
try:
(cls, id, payload_len) = struct.unpack("<BBH", bytes(data[2:6]))
Expand Down

0 comments on commit 9fc089b

Please sign in to comment.