Skip to content

Commit b5f4152

Browse files
committed
src: expose BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: nodejs-private/node-private#1002 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> CVE-ID: CVE-2026-111497
1 parent 49dff6f commit b5f4152

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎src/node_zlib.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,7 @@ void DefineZlibConstants(Local<Object> target) {
21502150
NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_FORMAT_PADDING_1);
21512151
NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_FORMAT_PADDING_2);
21522152
NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_FORMAT_DISTANCE);
2153+
NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH);
21532154
NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET);
21542155
NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_INVALID_ARGUMENTS);
21552156
NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES);

‎test/parallel/test-zlib-invalid-input.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,33 @@ Object.defineProperty(spoofedLength, 'byteLength', { get: () => 5000 });
8989
deflate.close();
9090
}
9191

92+
{
93+
// A block switch is invalid when the stream declares only one block type.
94+
const invalidBlockSwitch = Buffer.from(
95+
'200010414141fcffff07002228f00b60f7f41f000000',
96+
'hex',
97+
);
98+
const expectedError = {
99+
code: 'ERR__ERROR_FORMAT_BLOCK_SWITCH',
100+
errno: zlib.constants.BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH,
101+
};
102+
103+
assert.strictEqual(expectedError.errno, -17);
104+
assert.throws(
105+
() => zlib.brotliDecompressSync(invalidBlockSwitch),
106+
expectedError,
107+
);
108+
109+
const brotli = zlib.createBrotliDecompress();
110+
brotli.resume();
111+
brotli.on('error', common.expectsError(expectedError));
112+
brotli.on('end', common.mustNotCall());
113+
for (let i = 0; i < invalidBlockSwitch.length; i++) {
114+
brotli.write(invalidBlockSwitch.subarray(i, i + 1));
115+
}
116+
brotli.end();
117+
}
118+
92119
unzips.forEach(common.mustCall((uz, i) => {
93120
uz.on('error', common.mustCall());
94121
uz.on('end', common.mustNotCall());

0 commit comments

Comments
 (0)