GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — zlib: fix abort with decodeStrings: false · nodejs/node@b42c0cc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • zlib.js
  • test/parallel
    • test-zlib-decode-strings.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/zlib.js‎

Copy file name to clipboardExpand all lines: lib/zlib.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,13 @@ class ZlibBase extends Transform {
302302
);
303303
}
304304

305-
if (opts.encoding || opts.objectMode || opts.writableObjectMode) {
305+
if (opts.encoding || opts.objectMode || opts.writableObjectMode ||
306+
opts.decodeStrings === false) {
306307
opts = { ...opts };
307308
opts.encoding = null;
308309
opts.objectMode = false;
309310
opts.writableObjectMode = false;
311+
opts.decodeStrings = true;
310312
}
311313
}
312314

Collapse file

‎test/parallel/test-zlib-decode-strings.js‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
// Strings must be decoded before they reach the native handle, even when
4+
// decodeStrings: false is passed. This used to abort the process.
5+
6+
const common = require('../common');
7+
const assert = require('assert');
8+
const zlib = require('zlib');
9+
10+
const input = 'héllo wörld';
11+
12+
const pairs = [
13+
[zlib.createGzip, zlib.gunzipSync],
14+
[zlib.createDeflate, zlib.inflateSync],
15+
[zlib.createDeflateRaw, zlib.inflateRawSync],
16+
[zlib.createBrotliCompress, zlib.brotliDecompressSync],
17+
[zlib.createZstdCompress, zlib.zstdDecompressSync],
18+
];
19+
20+
for (const [createCompress, decompressSync] of pairs) {
21+
const compress = createCompress({ decodeStrings: false });
22+
const chunks = [];
23+
compress.on('data', (chunk) => chunks.push(chunk));
24+
compress.on('end', common.mustCall(() => {
25+
assert.strictEqual(decompressSync(Buffer.concat(chunks)).toString(), input);
26+
}));
27+
compress.end(input);
28+
}
29+
30+
zlib.gzip(input, { decodeStrings: false }, common.mustSucceed((compressed) => {
31+
assert.strictEqual(zlib.gunzipSync(compressed).toString(), input);
32+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.