-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zlib: fix decompression of empty data streams
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 <info@bnoordhuis.nl> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const zlib = require('zlib'); | ||
const { inspect, promisify } = require('util'); | ||
const assert = require('assert'); | ||
const emptyBuffer = new Buffer(0); | ||
|
||
common.crashOnUnhandledRejection(); | ||
|
||
(async function() { | ||
for (const [ compress, decompress, method ] of [ | ||
[ zlib.deflateRawSync, zlib.inflateRawSync, 'raw sync' ], | ||
[ zlib.deflateSync, zlib.inflateSync, 'deflate sync' ], | ||
[ zlib.gzipSync, zlib.gunzipSync, 'gzip sync' ], | ||
[ promisify(zlib.deflateRaw), promisify(zlib.inflateRaw), 'raw' ], | ||
[ promisify(zlib.deflate), promisify(zlib.inflate), 'deflate' ], | ||
[ promisify(zlib.gzip), promisify(zlib.gunzip), 'gzip' ] | ||
]) { | ||
const compressed = await compress(emptyBuffer); | ||
const decompressed = await decompress(compressed); | ||
assert.deepStrictEqual( | ||
emptyBuffer, decompressed, | ||
`Expected ${inspect(compressed)} to match ${inspect(decompressed)} ` + | ||
`to match for ${method}`); | ||
} | ||
})(); |