Skip to content

Read detached and out-of-bounds DataView chunks as empty - #7516

Merged
jasnell merged 1 commit into
mainfrom
jasnell/ts-streams-detached-dataview
Sep 26, 2026
Merged

jasnell merged 1 commit into
mainfrom
jasnell/ts-streams-detached-dataview

Conversation

@jasnell

@jasnell jasnell commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Fixup the handling of DataViews in the TS impl

@jasnell
jasnell requested review from guybedford and npaun September 24, 2026 22:16
@jasnell
jasnell requested review from a team as code owners September 24, 2026 22:16
@ask-bonk

ask-bonk Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@jasnell
jasnell force-pushed the jasnell/ts-streams-detached-dataview branch from b92e7b1 to 92d7f16 Compare September 25, 2026 23:05
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

The DataView byteOffset and byteLength getters throw a TypeError on a
view whose buffer is detached, or that a resizable buffer has shrunk out
from under; the typed-array getters report 0 for the same view. Five
TypeScript paths read caller-supplied views through those getters
unguarded, so such a DataView chunk:

- rejected an IdentityTransformStream / FixedLengthStream write;
- errored a CompressionStream / DecompressionStream (the write, later
  writes, close() and the readable all rejected);
- errored a DigestStream (its digest then never settles, as after any
  erroring write in either implementation);
- errored a native-backed writable with a highWaterMark (e.g. connect()
  with { highWaterMark }), whose byte-counting size callback threw;
- failed body collection (Response/Request of a JS value stream) when
  out of bounds; the drain loop already skipped detached views.

The C++ implementation treats all of these as zero-length, as both
implementations already did for typed arrays.

webstreams/view-extent.ts (a leaf module) reads a view's extent through
the captured getters and gives a DataView the typed arrays' answer:
viewByteLength() for the size paths (writable.ts byteSizeOf,
identity.ts byteSize, digest-stream.ts), viewByteExtent() where the
bytes are copied (identity.ts and compression.ts snapshots, readable.ts
collectChunks, replacing its detachment probe).

Pinned under both implementations: identity alreadyDetachedViewAtWrite
and outOfBoundsViewAtWrite now cover DataViews; new compression
degenerateViewsAreNoops, digest degenerateViewsHashAsEmpty, sockets
degenerateViewsWithHighWaterMark; readable
bodyConsumptionNormalizesBufferSourceChunks adds out-of-bounds views.
Each fails in the TypeScript cells without the fix. Behind the
experimental typescript_implemented_streams flag.
@jasnell
jasnell force-pushed the jasnell/ts-streams-detached-dataview branch from 92d7f16 to 68d99dd Compare September 25, 2026 23:24
@jasnell
jasnell enabled auto-merge September 25, 2026 23:29
@jasnell
jasnell merged commit e00e11a into main Sep 26, 2026
35 of 36 checks passed
@jasnell
jasnell deleted the jasnell/ts-streams-detached-dataview branch September 26, 2026 00:10
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.

2 participants