Skip to content

fix(core): avoid infinite THP error loop #5611

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

Merged
merged 2 commits into from
Aug 22, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion core/src/trezor/wire/thp/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async def recv_payload(

if expected_ctrl_byte is None or not expected_ctrl_byte(ctrl_byte):
if __debug__:
self._log("Unexpected control byte", utils.hexlify_if_bytes(msg))
self._log("Unexpected control byte: ", utils.hexlify_if_bytes(msg))
raise ThpError("Unexpected control byte")

# 2: Handle message with unexpected sequential bit
Expand Down
3 changes: 2 additions & 1 deletion core/src/trezor/wire/thp/session_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ async def handle(self, message: Message | None = None) -> None:
if __debug__:
log.exception(__name__, e, iface=self.iface)
await self.write(failure(e))
return
except UnexpectedMessageException as unexpected:
# The workflow was interrupted by an unexpected message. We need to
# process it as if it was a new message...
message = unexpected.msg
except Exception as exc:
# Log and try again.
if __debug__:
log.exception(__name__, exc, iface=self.iface)
return

async def _read_next_message(self) -> Message:
while True:
Expand Down