Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zlib fails when uncompressing a previously compressed empty buffer #17041

Closed
DiegoTUI opened this issue Nov 15, 2017 · 1 comment
Closed

zlib fails when uncompressing a previously compressed empty buffer #17041

DiegoTUI opened this issue Nov 15, 2017 · 1 comment
Assignees
Labels
confirmed-bug Issues with confirmed bugs. zlib Issues and PRs related to the zlib subsystem.

Comments

@DiegoTUI
Copy link
Contributor

DiegoTUI commented Nov 15, 2017

Zlib throws an exception when trying to decompress a previously compressed empty buffer. The code below does not enter any catch block in node 8.x.x, but enters all of them in node 9.1.0. It seems like the compression part behaves exactly the same in 8.x.x and 9.1.0, but the decompression part definitely not.

'use strict';

const assert = require('assert');
const zlib = require('zlib');
const emptyBuffer = new Buffer(0);
let compressed, decompressed

//deflateRawSync
compressed = zlib.deflateRawSync(emptyBuffer);
console.log(compressed);
try {
  decompressed = zlib.inflateRawSync(compressed);
  assert(decompressed.compare(emptyBuffer) === 0);
} catch (e) { console.log('deflateRawSync', e);}

//deflateSync
compressed = zlib.deflateSync(emptyBuffer);
console.log(compressed);
try {
  decompressed = zlib.inflateSync(compressed);
  assert(decompressed.compare(emptyBuffer) === 0);
} catch (e) { console.log('deflateSync', e);}

//gzipSync
compressed = zlib.gzipSync(emptyBuffer);
console.log(compressed);
try {
  decompressed = zlib.gunzipSync(compressed);
  assert(decompressed.compare(emptyBuffer) === 0);
} catch (e) { console.log('gzipSync', e);}

(edited by @addaleax: syntax highlighting)

@addaleax addaleax added zlib Issues and PRs related to the zlib subsystem. confirmed-bug Issues with confirmed bugs. labels Nov 15, 2017
@addaleax addaleax self-assigned this Nov 15, 2017
addaleax added a commit to addaleax/node that referenced this issue Nov 15, 2017
add4b0a made the assumption that compressed data
would never lead to an empty decompressed stream.

Fix that by explicitly checking the number of read bytes.

Fixes: nodejs#17041
Refs: nodejs#13322
MylesBorins pushed a commit that referenced this issue Dec 12, 2017
add4b0a made the assumption that compressed data
would never lead to an empty decompressed stream.

Fix that by explicitly checking the number of read bytes.

PR-URL: #17042
Fixes: #17041
Refs: #13322
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@ikishanoza
Copy link

Updating to latest stable version(10.15.0) of node solve the issue for me .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. zlib Issues and PRs related to the zlib subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants