GeezerVison is showing github.com — src: expose `BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH` · nodejs/node@b5f4152
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_zlib.cc +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2150,6 +2150,7 @@ void DefineZlibConstants(Local<Object> target) { |
2150 | 2150 | NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_FORMAT_PADDING_1); |
2151 | 2151 | NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_FORMAT_PADDING_2); |
2152 | 2152 | NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_FORMAT_DISTANCE); |
| 2153 | + NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH); |
2153 | 2154 | NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET); |
2154 | 2155 | NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_INVALID_ARGUMENTS); |
2155 | 2156 | NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-zlib-invalid-input.js +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -89,6 +89,33 @@ Object.defineProperty(spoofedLength, 'byteLength', { get: () => 5000 }); |
89 | 89 | deflate.close(); |
90 | 90 | } |
91 | 91 |
|
| 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 | + |
92 | 119 | unzips.forEach(common.mustCall((uz, i) => { |
93 | 120 | uz.on('error', common.mustCall()); |
94 | 121 | uz.on('end', common.mustNotCall()); |
|