zlib: fix decompression of empty data streams#17042
Closed
addaleax wants to merge 1 commit intonodejs:masterfrom
Closed
zlib: fix decompression of empty data streams#17042addaleax wants to merge 1 commit intonodejs:masterfrom
addaleax wants to merge 1 commit intonodejs:masterfrom
Conversation
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
bnoordhuis
approved these changes
Nov 15, 2017
Member
Author
lpinca
approved these changes
Nov 15, 2017
cjihrig
approved these changes
Nov 15, 2017
evanlucas
approved these changes
Nov 16, 2017
mcollina
approved these changes
Nov 16, 2017
| if (this.nread >= kMaxLength) { | ||
| err = new errors.RangeError('ERR_BUFFER_TOO_LARGE'); | ||
| } else if (this.nread === 0) { | ||
| buf = Buffer.alloc(0); |
Member
There was a problem hiding this comment.
I don't know if there is any performance penalty to use Buffer.alloc(0) vs Buffer.allocUnsafe(0). However, as it's 0 I would use allocUnsafe.
Member
Author
There was a problem hiding this comment.
alloc() has what is essentially a fast path for 0, allocUnsafe() doesn’t.
Member
There was a problem hiding this comment.
This is very interesting. thanks!
Member
Author
There was a problem hiding this comment.
I mean, I don’t think it’s that way on purpose. :) It just happens to align nicely with how we can use basically new Uint8Array(n) for the Buffer.alloc() fast path, whereas Buffer.allocUnsafe() needs a bit of setup.
jasnell
approved these changes
Nov 16, 2017
Member
Author
|
Landed in 01f853c |
addaleax
added a commit
that referenced
this pull request
Nov 18, 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 <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>
MylesBorins
pushed a commit
that referenced
this pull request
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 <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>
Merged
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: #17041
Refs: #13322
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
zlib