fix(core/embed): accept zero-length TLV item at the end of optiga metadata
What changed, and why it matters
This is a small bug fix in the Trezor hardware wallet firmware. It changes a bounds check so that a zero-length data item at the very end of a metadata block is accepted, just like zero-length items already are elsewhere in the block. Without the fix, a valid but empty trailing item would be rejected as malformed. This could cause communication problems with the Optiga security chip, but the change itself is a straightforward correction of an overly strict check.
Treat as a normal bug fix. Review whether the parser still rejects truly malformed inputs (e.g., length extending past the buffer) and verify that downstream callers handle the now-accepted empty trailing item safely. No urgent security response is indicated by the diff alone.
Security signals we found
Off-by-one bounds check in metadata parser
Parser previously rejected valid zero-length trailing TLV item
Change aligns final-position handling with non-final position handling
No explicit security impact described by vendor
Evidence from the diff
In optiga_parse_metadata(), the parser walks a TLV-style metadata buffer. The loop checks whether there are at least two bytes remaining (tag and length) before reading them. The old condition pos + 2 >= serialized_size rejected the case where exactly two bytes remain, which is actually valid because the length field can be zero, meaning the item has no value bytes. The new condition pos + 2 > serialized_size correctly allows reading the tag and length when exactly two bytes are left, matching the behavior for zero-length items at non-final positions. This is a classic off-by-one / boundary-condition fix.
Changed components
core/embed/sec/optiga/optiga_metadata.cOptiga metadata parsing routineInspect captured patch +1 / −1
### core/embed/sec/optiga/optiga_metadata.c
@@ -79,7 +79,7 @@ optiga_result optiga_parse_metadata(const uint8_t *serialized,
size_t pos = 2;
while (pos < serialized_size) {
- if (pos + 2 >= serialized_size) {
+ if (pos + 2 > serialized_size) {
return OPTIGA_ERR_PARAM;
}
Why this scored 42/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.