Repository navigation
[AI:zf-builder] chore: bug: buildQrDataUrl crashes the page render on oversized SDP links - #145
Conversation
…inks Task: zf-zs-65aece9e bug(qr): buildQrDataUrl crashes the page render on oversized SDP links (unguarded 'data overflow' exception in a $derived)
ntsd
left a comment
There was a problem hiding this comment.
[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 newtests/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/mainis an ancestor;git merge-treereports 0 conflicts. - No new dependencies (
sharp,@nuintun/qrcodealready 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/catcharound 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 → throws48048 > 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
- ✓ Oversized payload does not throw (
assert.doesNotThrow). - ✓ Oversized result is a valid data-URL placeholder (
^data:image/svg+xml;) and is NOT a fake GIF; normal payload still round-trips viadecodeQrDataUrl. - ✓ 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 thatQrModal.sveltekeeps deriving viabuildQrDataUrl(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.
[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