Skip to content

Commit ece624f

Browse files
committed
fix(python): raise ProtocolError on invalid THP continuation
[no changelog]
1 parent c65ec9c commit ece624f

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

python/src/trezorlib/thp/thp_io.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def read_and_assemble(transport: Transport, timeout: float | None = None) -> Mes
9595
FORMAT_STR_INIT, chunk[:INIT_HEADER_LENGTH]
9696
)
9797
except struct.error:
98-
raise exceptions.ProtocolError("Invalid header")
98+
raise exceptions.ProtocolError("Invalid message header")
9999

100100
if ctrl_byte == CONTINUATION_PACKET:
101101
LOG.warning("Skipping unexpected continuation packet")
@@ -116,9 +116,12 @@ def read_and_assemble(transport: Transport, timeout: float | None = None) -> Mes
116116
)
117117

118118
chunk = transport.read_chunk(timeout=timeout)
119-
ctrl_byte, cid = struct.unpack(
120-
FORMAT_STR_CONT, chunk[:CONT_HEADER_LENGTH]
121-
)
119+
try:
120+
ctrl_byte, cid = struct.unpack(
121+
FORMAT_STR_CONT, chunk[:CONT_HEADER_LENGTH]
122+
)
123+
except struct.error:
124+
raise exceptions.ProtocolError("Invalid continuation header")
122125
if ctrl_byte != CONTINUATION_PACKET:
123126
LOG.warning(
124127
"Expected continuation, got: %s",

0 commit comments

Comments
 (0)