Uh oh!
There was an error while loading. Please reload this page.
zlib: Allow zlib.gunzip features with zlib.unzip - #5884
Conversation
bnoordhuis
commented
Mar 24, 2016
LGTM. CI: https://ci.nodejs.org/job/node-test-pull-request/2051/ I asked you in the other PR to remove the defines but that was before I'd seen this PR. |
addaleax
commented
Mar 24, 2016
Sorry, even if CI passes, I’ll have to update this with a somewhat different approach and more tests. |
addaleax
commented
Mar 24, 2016
Okay, added a new commit with tests for the case that even the magic bytes don’t come in a single chunk (I know it’s quite an unlikely edge case, but I guess even that should be supported). The new test will require the bugfix from #5883 to pass, though. |
07ed63a to
fd10a48Comparekthelgason
commented
Mar 24, 2016
This looks like something that should obviously be supported. The only relevant bytes here are the first two bytes of the file, right? When would these be in separate chunks? |
addaleax
commented
Mar 24, 2016
Yes, these are the only inspected bytes. And honestly, I have no idea how they might get split into separate chunks. 😄 But it could, because we don’t have control about where the data comes from, and I think that means either not supporting this feature at all or creating an edge case in which it does not work. |
kthelgason
commented
Mar 24, 2016
I guess if someone set the chunksize to 1 when constructing a |
addaleax
commented
Mar 24, 2016
>zlib.createGunzip({chunkSize:1})
Error: Invalid chunksize: 1I guess you’re talking about something like receiving |
kthelgason
commented
Mar 24, 2016
Actually, your example is exactly what I was thinking of, but I'm happy to see that it isn't possible. But obviously one can construct pathological cases where this would happen, like passing one byte at a time to Anyway, I give this a big 👍, thanks for improving on this 😃 |
addaleax
commented
Mar 24, 2016
I think that should be covered by the test cases here, but I guess you can feel free to create more of them. And again, good to have you on board with this! 😄 |
There was a problem hiding this comment.
Quick question: would it be necessary to check that ctx->strm_.avail_in > 0 before trying to read the first byte?
There was a problem hiding this comment.
In that vein, shouldn't there be a similar check for GZIP_HEADER_ID2?
Another question: what happens when the state machines sees GZIP_HEADER_ID1 followed by a byte that's not GZIP_HEADER_ID2? Is the first byte lost?
There was a problem hiding this comment.
Sorry, you’re right – updated again. And no, no bytes are lost in that case; there is always the fall-through in the outer switch from case UNZIP: to case INFLATE:, so all input ends up being passed to inflate().
fd10a48 to
2598a0fCompareaddaleax
commented
Mar 31, 2016
Rebased and updated with your suggestion; The tests are passing now that #5883 is merged. |
2598a0f to
a388a5eComparejasnell
commented
Apr 1, 2016
LGTM if @bnoordhuis is happy. |
jasnell
commented
Apr 1, 2016
bnoordhuis
commented
Apr 1, 2016
LGTM with the style nit that comments should be capitalized and punctuated. |
Detect whether a gzip file is being passed to `unzip*` by testing the first bytes for the gzip magic bytes, and setting the decompression mode to `GUNZIP` or `INFLATE` according to the result. This enables gzip-only features like multi-member support to be used together with the `unzip*` autodetection support and thereby makes `gunzip*` and `unzip*` return identical results for gzip input again. Add a simple test for checking that features specific to `zlib.gunzip`, notably support for multiple members, also work when using `zlib.unzip`.
a388a5e to
a8e1fb5Compareaddaleax
commented
Apr 2, 2016
Updated the comments. :) |
bnoordhuis
commented
Apr 5, 2016
Thanks Anna, landed in 2d7e316. |
Detect whether a gzip file is being passed to `unzip*` by testing the first bytes for the gzip magic bytes, and setting the decompression mode to `GUNZIP` or `INFLATE` according to the result. This enables gzip-only features like multi-member support to be used together with the `unzip*` autodetection support and thereby makes `gunzip*` and `unzip*` return identical results for gzip input again. Add a simple test for checking that features specific to `zlib.gunzip`, notably support for multiple members, also work when using `zlib.unzip`. PR-URL: #5884 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Detect whether a gzip file is being passed to `unzip*` by testing the first bytes for the gzip magic bytes, and setting the decompression mode to `GUNZIP` or `INFLATE` according to the result. This enables gzip-only features like multi-member support to be used together with the `unzip*` autodetection support and thereby makes `gunzip*` and `unzip*` return identical results for gzip input again. Add a simple test for checking that features specific to `zlib.gunzip`, notably support for multiple members, also work when using `zlib.unzip`. PR-URL: #5884 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Detect whether a gzip file is being passed to `unzip*` by testing the first bytes for the gzip magic bytes, and setting the decompression mode to `GUNZIP` or `INFLATE` according to the result. This enables gzip-only features like multi-member support to be used together with the `unzip*` autodetection support and thereby makes `gunzip*` and `unzip*` return identical results for gzip input again. Add a simple test for checking that features specific to `zlib.gunzip`, notably support for multiple members, also work when using `zlib.unzip`. PR-URL: #5884 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Pull Request check-list
make -j8 test(UNIX) orvcbuild test nosign(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
Affected core subsystem(s)
zlib
Description of change
Detect whether a gzip file is being passed to
unzip*by testing the first bytes for the gzip magic bytes, and setting the decompression mode toGUNZIPorINFLATEaccording to the result.This enables gzip-only features like multi-member support to be used together with the
unzip*autodetection support and thereby makesgunzip*andunzip*return identical results for gzip input again.This is more or less a follow-up change to #5120.