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: check if message can be handled before attempting to deserialize #5927

Merged
merged 1 commit into from
Mar 12, 2024
Merged
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
9 changes: 5 additions & 4 deletions contrib/message-capture/message-capture-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,20 @@ def process_file(path: str, messages: List[Any], recv: bool, progress_bar: Optio
msg_ser = BytesIO(f_in.read(length))

# Determine message type
if msgtype not in MESSAGEMAP:
# Unrecognized message type
if msgtype not in MESSAGEMAP or MESSAGEMAP[msgtype] is None:
# Unrecognized or unhandled message type
try:
msgtype_tmp = msgtype.decode()
if not msgtype_tmp.isprintable():
raise UnicodeDecodeError
msg_dict["msgtype"] = msgtype_tmp
except UnicodeDecodeError:
msg_dict["msgtype"] = "UNREADABLE"
err_str = "Unrecognized" if msgtype not in MESSAGEMAP else "Unhandled"
msg_dict["body"] = msg_ser.read().hex()
msg_dict["error"] = "Unrecognized message type."
msg_dict["error"] = f"{err_str} message type"
messages.append(msg_dict)
print(f"WARNING - Unrecognized message type {msgtype} in {path}", file=sys.stderr)
print(f"WARNING - {msg_dict['error']} {msgtype} in {path}", file=sys.stderr)
continue

# Deserialize the message
Expand Down
Loading