Cross-origin handoff, retained byte cap, typed preview Blob, native picker
user activation and first-seen-source GAP each get an input that only that
rule rejects. Removing any of the five lines now fails exactly one test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preview and download share one lease registry and download leases stay for a
30 s grace, so running out of slots clears on its own. Only a Blob above the
single-lease ceiling stays LIMIT_EXCEEDED without retry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
create() checked the signal only before resolving the file, so an abort in
the same turn still produced a lease the caller never released. Each leak
used one of the 16 object URL slots shared with downloads.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The exact media-type regex lived in object-url-lease.ts,
browser-file-policy-registry.ts and the download validation;
safeOpaqueValue (vault) and safeGeneratedToken (download) were the same
regex; and five modules each defined their own positive-safe-integer check
(isPositiveByteLimit included). file-policy.ts now exports one copy of each:
EXACT_MEDIA_TYPE, isSafeGeneratedToken, isPositiveSafeInteger.
ObjectUrlLeaseRegistry.create also loses an inner revoke branch that could
never run (it required a non-empty string inside a "not a non-empty string"
guard).
cache-storage/public-cache-policy.ts keeps its private positiveSafeInteger:
adapters may not import another adapter's module.
Verified: a characterization test (unsafe reference -> UNAVAILABLE, 128-char
token accepted, empty object URL -> no revoke, fractional/zero limits and a
wildcard download media type rejected) passes on the code before and after.
Lane gates pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sanitizeSuggestedFileName dropped one code point at a time and re-encoded the
whole name each round, so a 100k-character server-supplied name took ~10^10
steps. truncateUtf8 now walks the code points once, counting UTF-8 bytes, and
cuts at the longest fitting prefix (trailing whitespace trimmed, as before).
The fallback base name uses the same helper. deliver() also sanitized the
name twice (validation, then again for use); validateDownloadInput now
returns the sanitized name and deliverActive uses it.
Verified: new unit test pins results for ASCII, Hangul, emoji and the
whitespace-trim case, and asserts a 5k-character name needs <10
TextEncoder.encode calls (RED before: 4827). Lane gates pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
download-delivery-adapter and browser-file-vault each carried their own
combineAbortSignals/awaitWithSignal copies. Two gaps followed:
- a presigned lease that resolved after the abort but before the delivery's
finally was seen by neither compensateLateSource (holder not yet closed) nor
closeHeldSource (lease never adopted), so it leaked;
- a writable from handle.createWritable() that arrived after the abort was
never aborted (Chrome keeps a .crswap file).
Each delivery and each vault stream now owns a createAbortableOperation joined
to the caller signal; dispose() closes the live owners. Every await goes
through owner.race, and late leases/writables are compensated by the race.
The hand-rolled abort ratchet drops 21 -> 19.
Verified: two new download tests (same-turn late lease, late writable) failed
before (close 0 times, no abort) and pass now; a new vault characterization
test (caller abort / dispose during a pending read) passes before and after.
All lane gates pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>