Skip to content

Harden QR parser against malformed inputs - #1064

Closed
knorrium wants to merge 2 commits into
SeedSigner:devfrom
knorrium:harden-parser-crashes-v2
Closed

knorrium wants to merge 2 commits into
SeedSigner:devfrom
knorrium:harden-parser-crashes-v2

Conversation

@knorrium

Copy link
Copy Markdown

Description

Supersedes #1039, rebased onto the current dev (after #995 and the OP_RETURN parsing rework).

Problem or Issue being addressed

Malformed QR input to the SettingsQR and signmessage parsers still raises uncaught IndexError / ValueError instead of being rejected in-band. On the device this shows up as the unhandled-exception screen, or in the signmessage case a silent return to the Main Menu with no error shown.

A PSBT whose external output pays to a script embit can't render as an address (bare multisig, OP_TRUE, an empty script, ...) also escapes the parse with a bare ValueError from script_pubkey.address(), which PSBTOverviewView doesn't catch.

Solution

  • Settings.parse_settingsqr(): raise InvalidSettingsQRData for a header with no settings, an empty name=, and an entry with no =.
  • SignMessageQrDecoder.add(): return DecodeQRStatus.INVALID when the {derivation_path} {fmt}:{message} part is missing or truncated.
  • DecodeQR.add_data(): when a recognized decoder returns INVALID, set qr_type = INVALID so ScanView routes to ScanInvalidQRTypeView instead of falling through to the Main Menu.
  • PSBTParser._parse_outputs(): raise a new PSBTUnsupportedOutputScriptError (a PSBTVerificationError) when an external output has no address representation. It routes to a new PSBTUnsupportedOutputScriptView, a Warning-level discard screen modeled on PSBTMalformedOpReturnView.

Additional Information

Compared with #1039, the old psbt_parser.py changes were dropped:

What's still missing is the unrecognized output case above.

Sample SeedQR to sign the psbt (set the network to regtest):

model ensure search plunge galaxy firm exclude brain satoshi meadow cable roast

00_signer_seedqr

Sample payload QRs (all fail on current dev):

01_settings_header_only 02_settings_empty_name 03_signmessage_truncated 05_settings_entry_without_equals 06_psbt_unsupported_output_script
01 settings::v1
02 settings::v1 name=
03 signmessage m
05 settings::v1 not-a-key-value
06 (base64 PSBT, 484 chars, single sig native segwit with an OP_TRUE external output; see 06_psbt_unsupported_output_script.png)

Screenshots

Before and after:

before_after_error_screens

The SettingsQR cases still land on the generic error screen, which is how SettingsIngestSettingsQRView routes a parse failure today. They now show a readable InvalidSettingsQRData message instead of an IndexError / ValueError.


This pull request is categorized as a:

  • New feature
  • Bug fix
  • Code refactor
  • Documentation
  • Other

Checklist

I ran pytest locally

  • All tests passed before submitting the PR (except the 5 l10n tests, which also fail on clean dev without compiled translations)

I added or updated tests

  • Yes

…s-v2

# Conflicts:
#	src/seedsigner/models/psbt_parser.py
#	tests/test_flows_psbt.py
#	tests/test_psbt_parser.py
@knorrium

Copy link
Copy Markdown
Author

@newtonick @kdmukai just resolved the merge conflicts again

@knorrium

Copy link
Copy Markdown
Author

@newtonick do you want to take another look before we run into merge conflicts again? 😄

@knorrium knorrium closed this Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant