Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fcf2a9f

Browse filesBrowse files
panvaaduh95
authored andcommitted
stream: fix brotli error handling in web compression streams
Convert brotli decompression errors to TypeError to match the Compression Streams spec, by extending handleKnownInternalErrors() in the adapters layer to recognize brotli error codes. This replaces the manual error event handler on DecompressionStream which was redundant with the adapter's built-in error propagation. PR-URL: #62107 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mattias Buelens <mattias@buelens.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
1 parent cdec579 commit fcf2a9f
Copy full SHA for fcf2a9f

3 files changed

+26-9Lines changed: 26 additions & 9 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/webstreams/adapters.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/adapters.js
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,14 @@ function handleKnownInternalErrors(cause) {
120120
case cause?.code === 'ERR_STREAM_PREMATURE_CLOSE': {
121121
return new AbortError(undefined, { cause });
122122
}
123-
case ZLIB_FAILURES.has(cause?.code): {
123+
case ZLIB_FAILURES.has(cause?.code):
124+
// Brotli decoder error codes are formatted as 'ERR_' +
125+
// BrotliDecoderErrorString(), where the latter returns strings like
126+
// '_ERROR_FORMAT_...', '_ERROR_ALLOC_...', '_ERROR_UNREACHABLE', etc.
127+
// The resulting JS error codes all start with 'ERR__ERROR_'.
128+
// Falls through
129+
case cause?.code != null &&
130+
StringPrototypeStartsWith(cause.code, 'ERR__ERROR_'): {
124131
// eslint-disable-next-line no-restricted-syntax
125132
const error = new TypeError(undefined, { cause });
126133
error.code = cause.code;
Collapse file

‎test/parallel/test-webstreams-compression-bad-chunks.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-webstreams-compression-bad-chunks.js
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,21 @@ for (const format of ['deflate', 'deflate-raw', 'gzip', 'brotli']) {
5555
});
5656
}
5757
}
58+
59+
// Verify that decompression errors (e.g. corrupt data) are surfaced as
60+
// TypeError, not plain Error, per the Compression Streams spec.
61+
for (const format of ['deflate', 'deflate-raw', 'gzip', 'brotli']) {
62+
test(`DecompressionStream surfaces corrupt data as TypeError for ${format}`, async () => {
63+
const ds = new DecompressionStream(format);
64+
const writer = ds.writable.getWriter();
65+
const reader = ds.readable.getReader();
66+
67+
const corruptData = new Uint8Array([0, 1, 2, 3, 4, 5]);
68+
69+
writer.write(corruptData).catch(() => {});
70+
reader.read().catch(() => {});
71+
72+
await assert.rejects(writer.close(), { name: 'TypeError' });
73+
await assert.rejects(reader.closed, { name: 'TypeError' });
74+
});
75+
}
Collapse file

‎test/wpt/status/compression.json‎

Copy file name to clipboardExpand all lines: test/wpt/status/compression.json
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
{
2-
"decompression-bad-chunks.any.js": {
3-
"fail": {
4-
"expected": [
5-
"chunk of type invalid deflate bytes should error the stream for brotli",
6-
"chunk of type invalid gzip bytes should error the stream for brotli"
7-
]
8-
}
9-
},
102
"compression-with-detach.window.js": {
113
"requires": ["crypto"]
124
},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.