Repository navigation
fix(decode_qr): validate signmessage QR payload structure before indexing (fixes #1058) - #1059
muskan-creates352 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
LGTM. Reviewed the changes and tested the decoder thoroughly.
The fix resolves the unhandled IndexError reported in #1058 when scanning incomplete signmessage QR codes. All 6 unit tests added in tests/test_sign_message_qr_decoder.py pass as expected.
Apart from the tests included in the PR, I also verified the decoder against these additional payloads:
| Payload | Decoder Status | Result |
|---|---|---|
signmessage ascii:hello |
INVALID |
Missing derivation path token caught |
signmessage m/84h/0h/0h :msg |
INVALID |
Missing format prefix before colon rejected |
signmessage m/84h/0h/0h ASCII:Hello |
INVALID |
Case-sensitive format requirement enforced |
signmessage m/84h/0h/0h ascii: |
COMPLETE |
Empty message parsed safely without exception |
signmessage m/84h/0h/0h ascii:Line 1\nLine 2 |
COMPLETE |
Multi-line messages preserved |
signmessage m/84h/0h/0h ascii:Time: 12:00:00 |
COMPLETE |
Multiple colons inside message text preserved |
signmessage m/84h/0h/0h ascii:A B |
COMPLETE |
Irregular inter-token whitespace handled |
signmessage m/84'/0'/0'/0/0 ascii:Hello |
COMPLETE |
Pre-normalized single-quote derivation path supported |
Valid signmessage payloads continue to decode without regression.
Also, kindly follow the repository PR template (.github/pull_request_template.md).
|
For additional context, I came across a few edge cases that fall slightly outside this decoder patch, but may be worth noting or addressing in a follow-up:
None of these are regressions from this PR, but tracking them could help make the sign-message pipeline fully robust end-to-end. |
|
Thank you so much for the thorough review and testing across all those edge cases, @wolffgang1729! Really appreciate the detailed feedback. Regarding the additional downstream cases and command/format token handling you mentioned, I would be more than happy to tackle them in follow-up issues and PRs once this lands! |
Fixes #1058
Description
When scanning a single-frame QR payload starting with
signmessage,SignMessageQrDecoder.add()previously performed direct indexing onparts[1],parts[2], and format splitting without validating the structure first. Scanning an incomplete or malformed QR code (e.g.signmessageorsignmessage m/84h/0h/0h) resulted in an unhandledIndexError: list index out of rangeand a crash rather than returningDecodeQRStatus.INVALID.Changes Made
src/seedsigner/models/decode_qr.py:len(parts) >= 3before accessing positional elements.:inparts[2].f"{fmt}:".DecodeQRStatus.INVALIDgracefully with informative logging if validation fails.tests/test_sign_message_qr_decoder.py:SignMessageQrDecoder.signmessagepayload decoding and derivation path normalization.IndexErroris raised).Testing
6 passed in 0.27s).