Skip to content

[AI:zf-builder] chore: bug: buildQrDataUrl crashes the page render on oversized SDP links - #145

Merged
ntsd merged 1 commit into
mainfrom
task/zf-zs-65aece9e
Nov 6, 2026
Merged

ntsd merged 1 commit into
mainfrom
task/zf-zs-65aece9e

Conversation

@ntsd

@ntsd ntsd commented Nov 6, 2026

Copy link
Copy Markdown
Owner

[AI:zf-builder] Task: zf-zs-65aece9e

bug(qr): buildQrDataUrl crashes the page render on oversized SDP links (unguarded 'data overflow' exception in a $derived)

Automated PR for task zf-zs-65aece9e

Completed by: @zf-builder

…inks

Task: zf-zs-65aece9e

bug(qr): buildQrDataUrl crashes the page render on oversized SDP links (unguarded 'data overflow' exception in a $derived)

@ntsd ntsd left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI:zf-reviewer] [Reviewer Feedback] Round 1: Ponytail Gatekeeping & Correctness — Approved for human review.

Verdict: APPROVE (Auto-Merge active — merge on approval)

Gate results (all green, run in worktree)

  • npm run test — 73 pass / 0 fail (includes the new tests/qr-overflow.test.mjs, 7/7 pass).
  • npm run lint — Prettier + ESLint clean.
  • npm run typecheck — clean.
  • npm run build — 2 pages built, complete.
  • Mergeability: origin/main is an ancestor; git merge-tree reports 0 conflicts.
  • No new dependencies (sharp, @nuintun/qrcode already declared). No lockfile drift.

Ponytail 7-Rung check — clean, minimal diff

  • Rung 7 (Diff Scope): Only 2 files in scope — src/utils/qr.ts (fix) + tests/qr-overflow.test.mjs (regression). No drive-by reformat, no churn, no leftover debug. Doc comment update is task-relevant. ✓
  • Rungs 3 & 5 (Dependency Veto): No new packages. Fallback uses a static SVG data: URL (module-level constant) — zero new deps. ✓
  • Rungs 1 & 6 (Simplicity/YAGNI): Fix is the simplest correct form — a try/catch around the existing encoder call returning a constant placeholder. No premature abstraction, no factory, no wrapper class. The builder chose the spec's preferred strategy (placeholder on overflow) over the size-probe alternative, and documented the choice in code — exactly as recommended. ✓

Correctness verification

I reproduced the real overflow boundary against the installed @nuintun/qrcode (M level, version:0 auto) to confirm the regression guard is NOT vacuous:

  • 2002-byte payload → encodes fine (data:image/gif) — the "no false fallback" test pins the real boundary.
  • 2334 / 2400 / 3002-byte payloads → throws data overflow: N > 18672 — the overflow path the fix guards.
  • 3002-byte non-ASCII (é) payload → throws 48048 > 18672, caught by the same guard.
    So the guard bites exactly where it should.

The fix keeps buildQrDataUrl a pure function of its input (module-level constant placeholder, no side effects), preserving the determinism assertion in tests/qr.test.mjs and the new determinism tests in tests/qr-overflow.test.mjs. The non-ASCII ECI round-trip behavior for payloads that DO fit is unchanged (QRByte(data) built-in UTF-8 path untouched).

Test adequacy — meets all 3 required regression assertions

  1. ✓ Oversized payload does not throw (assert.doesNotThrow).
  2. ✓ Oversized result is a valid data-URL placeholder (^data:image/svg+xml;) and is NOT a fake GIF; normal payload still round-trips via decodeQrDataUrl.
  3. ✓ Determinism on oversized input (identical → identical placeholder; all oversized → same constant).
    Plus a boundary test (fits at ~2 KB → real GIF) and a static source-guard that QrModal.svelte keeps deriving via buildQrDataUrl(qrData) — matching the repo's static-source-guard convention.

Security note

Placeholder SVG is safe: built from a static literal run through encodeURIComponent, and consumed only as an <img src> (never srcdoc/innerHTML/<object>), so no script-execution vector. No user-controlled input reaches the placeholder string.

Mergeability

No conflicts with main; clean working tree; all gates pass. Approving for human review / auto-merge.


CONVENTION: Regression guards for overflow/crash fixes must prove the guard BITES against the installed library (assert the real encode/throw boundary — e.g. 2002B fits, 3002B throws data overflow) and pin a same-shape boundary test so the fallback doesn't fire on payloads the encoder can actually hold.
GOTCHA: A render-critical pure helper called inside a Svelte $derived must degrade (static placeholder) on ANY synchronous encoder exception, not just the documented data overflow shape — a narrow catch (e) { if (e.message) ... } would still crash the page on other encoder failures; a bare catch {} returning a module-level constant is the minimal correct form.

@ntsd
ntsd merged commit c9f5dba into main Nov 6, 2026
1 check passed
@ntsd
ntsd deleted the task/zf-zs-65aece9e branch November 6, 2026 15:13
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