Skip to content

Unbounded P2MR proof parsing can block the qbit-qt event loop #93

Closed

Description

@kiwidream

Summary

The qbit-qt P2MR proof editor does not impose a content-size limit. Clicking Verify synchronously copies and parses the entire supplied JSON document on the GUI thread.

Fixed-size hex fields are decoded before their decoded sizes are checked. Variable-size fields such as leaf_script and control_block are also decoded without an input bound.

Impact

A very large proof supplied by a counterparty and pasted into qbit-qt can cause large transient allocations and block the GUI event loop until parsing and decoding finish. At sufficiently large sizes, this may exhaust available memory.

The work is linear in the pasted input and has no known amplification. Practical latency and memory thresholds still need measurement, but malformed input should be rejected before expensive conversion and decoding.

Steps to reproduce

  1. Start with a structurally valid P2MR proof JSON document.
  2. Replace one field with a tens- or hundreds-of-megabytes value, testing:
    • signature;
    • pubkey;
    • message_hash;
    • leaf_script; and
    • control_block.
  3. Also test an oversized whole document or deeply malformed JSON.
  4. Paste the document into qbit-qt Sign/Verify and click Verify.
  5. Measure event-loop latency and peak memory.
  6. Observe that the current path copies and parses the document, and may hex-decode the oversized field, before rejecting its protocol size.

Relevant code

The P2MR proof UI was added in #63.

Desired outcome

  • Define a conservative maximum serialized proof size based on the largest valid proof.
  • Reject an oversized document before UTF-8 conversion or JSON parsing, for example by checking the document character count before copying its contents.
  • Check fixed-size hex character counts before calling ParseHex.
  • Bound leaf_script and control_block against their applicable protocol maxima before allocation or decoding.
  • Return a normal validation error promptly and clear any stale successful verification state.

Suggested tests

Add coverage for:

  • a document one byte below, at, and above the total limit;
  • every fixed-size field below and above its required hex length;
  • over-limit leaf_script and control_block;
  • malformed nesting and duplicate fields; and
  • continued successful verification of the largest valid proof.

Add a supported-platform benchmark recording rejection latency and peak memory for representative oversized inputs.

Version and platform

  • Source-inspected on main at 7e48b45f2a8e75268fd1fd44d0091a4bdde2377e.
  • Also applies to 1.0.0 at 68a12571bcb56597c4865abce474a6cc3d356fc3; the relevant files are identical.
  • Applies to all qbit-qt platforms; latency and memory impact will depend on the host.

Activity

  1. added
    bug
    on Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions