chore(python): remove `magic` and `code_length` fields from `LegacyFirmware` struct
What changed, and why it matters
This is a small internal cleanup in the Python helper library that handles Trezor One firmware files. It removes two exposed fields ('magic' and 'code_length') from a Python class and renames them to private internal names ('_magic' and '_code_length'). The actual binary parsing behavior is unchanged: the 'TRZR' magic bytes are still required, and the code length is still computed and embedded exactly as before. There is no security fix or vulnerability here.
No security action needed. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In python/src/trezorlib/firmware/legacy.py, the LegacyFirmware dataclass/struct loses the ‘magic: bytes’ and ‘code_length: int’ annotations. In the construct SUBCON, those fields are renamed to ‘magic’ and ‘_code_length’ (prefixed with underscore, conventionally private). The c.Const(b’TRZR’) and c.Rebuild(c.Int32ul, c.len(c.this.code)) definitions remain identical, and the ‘code’ field still references c.this._code_length. This is a pure API/struct-cleanup refactor with no behavioral change to serialization, deserialization, or validation.
Changed components
python/src/trezorlib/firmware/legacy.pyInspect captured patch +3 / −5
diff --git a/python/src/trezorlib/firmware/legacy.py b/python/src/trezorlib/firmware/legacy.py
index a975d49e..8c8f5ef1 100644
--- a/python/src/trezorlib/firmware/legacy.py
+++ b/python/src/trezorlib/firmware/legacy.py
@@ -180,8 +180,6 @@ class LegacyFirmware(SanityCheckedStruct):
expected format of firmware binary for Trezor One version 1.8.0, which can be installed
by both the older and the newer bootloader."""
- magic: bytes
- code_length: int
key_indexes: list[int]
reserved: bytes
signatures: list[bytes]
@@ -191,8 +189,8 @@ class LegacyFirmware(SanityCheckedStruct):
# fmt: off
SUBCON = c.Struct(
- "magic" / c.Const(b"TRZR"),
- "code_length" / c.Rebuild(c.Int32ul, c.len_(c.this.code)),
+ "_magic" / c.Const(b"TRZR"),
+ "_code_length" / c.Rebuild(c.Int32ul, c.len_(c.this.code)),
"key_indexes" / c.Int8ul[consts.V1_SIGNATURE_SLOTS], # pylint: disable=E1136
"flags" / c.BitStruct(
"reserved" / c.BitsInteger(7),
@@ -200,7 +198,7 @@ class LegacyFirmware(SanityCheckedStruct):
),
"reserved" / Reserved(52),
"signatures" / c.Bytes(64)[consts.V1_SIGNATURE_SLOTS],
- "code" / c.Bytes(c.this.code_length),
+ "code" / c.Bytes(c.this._code_length),
c.Terminated,
"embedded_v2" / c.RestreamData(c.this.code, c.Optional(LegacyV2Firmware.SUBCON)),
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.