Files
node/test/parallel/test-zlib-decode-strings.js
T
James Ross b42c0ccfa3 zlib: fix abort with decodeStrings: false
Passing decodeStrings: false to a zlib stream, or to an async
convenience method, let strings reach the native handle, which
aborts the process on its Buffer check. Force decodeStrings back to
true, as is already done for encoding and objectMode.

Signed-off-by: James Ross <james@jross.me>
PR-URL: https://github.com/nodejs/node/pull/66359
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2026-09-29 21:48:17 +00:00

33 lines
1.0 KiB
JavaScript

'use strict';
// Strings must be decoded before they reach the native handle, even when
// decodeStrings: false is passed. This used to abort the process.
const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');
const input = 'héllo wörld';
const pairs = [
[zlib.createGzip, zlib.gunzipSync],
[zlib.createDeflate, zlib.inflateSync],
[zlib.createDeflateRaw, zlib.inflateRawSync],
[zlib.createBrotliCompress, zlib.brotliDecompressSync],
[zlib.createZstdCompress, zlib.zstdDecompressSync],
];
for (const [createCompress, decompressSync] of pairs) {
const compress = createCompress({ decodeStrings: false });
const chunks = [];
compress.on('data', (chunk) => chunks.push(chunk));
compress.on('end', common.mustCall(() => {
assert.strictEqual(decompressSync(Buffer.concat(chunks)).toString(), input);
}));
compress.end(input);
}
zlib.gzip(input, { decodeStrings: false }, common.mustSucceed((compressed) => {
assert.strictEqual(zlib.gunzipSync(compressed).toString(), input);
}));