FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

zlib: fix decompression of empty data streams by addaleax · Pull Request #17042 · nodejs/node · GitHub

/ node Public

zlib: fix decompression of empty data streams - #17042

Closed
addaleax wants to merge 1 commit into
nodejs:masterfrom
addaleax:zlib-empty
Closed

zlib: fix decompression of empty data streams#17042
addaleax wants to merge 1 commit into
nodejs:masterfrom
addaleax:zlib-empty

Conversation

Copy link
Copy Markdown
Member

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

zlib

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
addaleax added dont-land-on-v6.x zlib Issues and PRs related to the zlib subsystem. labels Nov 15, 2017

Copy link
Copy Markdown
Member Author

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM with a nit.

Comment thread lib/zlib.js
if (this.nread >= kMaxLength) {
err = new errors.RangeError('ERR_BUFFER_TOO_LARGE');
} else if (this.nread === 0) {
buf = Buffer.alloc(0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

alloc() has what is essentially a fast path for 0, allocUnsafe() doesn’t.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is very interesting. thanks!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member Author

Landed in 01f853c

addaleax closed this Nov 18, 2017
addaleax deleted the zlib-empty branch November 18, 2017 19:41
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>
MylesBorins mentioned this pull request Dec 12, 2017
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

Labels

zlib Issues and PRs related to the zlib subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zlib fails when uncompressing a previously compressed empty buffer

7 participants


Back | FazBrowse Home | New Git URL