-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Fix zlib pseudo multi member failure #5863
Fix zlib pseudo multi member failure #5863
Conversation
@@ -258,7 +258,7 @@ class ZCtx : public AsyncWrap { | |||
} | |||
} | |||
while (ctx->strm_.avail_in >= GZIP_MIN_HEADER_SIZE && | |||
ctx->mode_ == GUNZIP) { | |||
ctx->mode_ == GUNZIP && ctx->err_ == Z_STREAM_END) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny style nit: can you put last clause on a separate line?
Would it be possible to shrink the test fixtures? We distribute the test suite and they add another 128 kB. |
// files that have the "right" magic bytes for starting a new gzip member | ||
// in the middle of themselves, even if they are part of a single | ||
// regularly compressed member | ||
const pmmFile = path.join(common.fixturesDir + '/pseudo-multimember-gzip'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're using path.join
here it should be path.join(common.fixturesDir, 'pseudo-multimember-gzip');
rather than concat the strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… silly me 😄
6375567
to
84be337
Compare
Updated with your suggestions. I’ll see what I can do about the file sizes – it’s just not that easy to get specific bytes at specific positions in gzipped files. 😄 |
84be337
to
74d56e0
Compare
Okay, was easier than I thought, both files are now just a few hundred bytes together. |
Nice, thanks. LGTM. CI: https://ci.nodejs.org/job/node-test-pull-request/2040/ |
}) | ||
.on('data', (data) => pmmResultBuffers.push(data)) | ||
.on('finish', common.mustCall(() => { | ||
assert.deepEqual(Buffer.concat(pmmResultBuffers), pmmExpected, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deepStrictEqual
might be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, why not. Updated using assert.deepStrictEqual
.
LGTM minus a nit, CI failure is unrelated. |
74d56e0
to
4e4c3c2
Compare
Add test files that reliably reproduce nodejs#5852. The gzipped file in test/fixtures/pseudo-multimember-gzip.gz contains the gzip magic bytes exactly at the position that node encounters after having read a single block, leading it to believe that a new data member is starting.
Only treat the gzip magic bytes, when encountered within the file after reading a single block, as the start of a new member when the previous member has ended. Fixes: nodejs#5852
4e4c3c2
to
1b2900f
Compare
LGTM |
LGTM |
Wow, that was obvious in retrospect. Thanks! |
Only treat the gzip magic bytes, when encountered within the file after reading a single block, as the start of a new member when the previous member has ended. Add test files that reliably reproduce #5852. The gzipped file in test/fixtures/pseudo-multimember-gzip.gz contains the gzip magic bytes exactly at the position that node encounters after having read a single block, leading it to believe that a new data member is starting. Fixes: #5852 PR-URL: #5863 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Thanks! Landed in 0b3936b :) |
@addaleax the other edge-case you mentioned, do you mean that another member is starting but less that 10 bytes remain in the input buffer? I think you're right that this might occur (although pretty unlikely). We only actually need to check if there are two bytes remaining, enough for the magic byte comparison. Then again even with that change, the edge-case still exists, albeit even less likely. If f.x. only one byte remains in the input buffer, in which case the output would be truncated anyway. |
@kthelgason Yes, that’s what I’m talking about. I’ll try and see whether I can get a test case for that together, but I agree, it’s definitely not very likely to occur in the wild. |
Only treat the gzip magic bytes, when encountered within the file after reading a single block, as the start of a new member when the previous member has ended. Add test files that reliably reproduce #5852. The gzipped file in test/fixtures/pseudo-multimember-gzip.gz contains the gzip magic bytes exactly at the position that node encounters after having read a single block, leading it to believe that a new data member is starting. Fixes: #5852 PR-URL: #5863 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Only treat the gzip magic bytes, when encountered within the file after reading a single block, as the start of a new member when the previous member has ended. Add test files that reliably reproduce #5852. The gzipped file in test/fixtures/pseudo-multimember-gzip.gz contains the gzip magic bytes exactly at the position that node encounters after having read a single block, leading it to believe that a new data member is starting. Fixes: #5852 PR-URL: #5863 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.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
Fixes #5852, which was introduced in f380db2 (#5120).
Only treat the gzip magic bytes, when encountered within the file after reading a single block, as the start of a new member when the previous member has ended.
I’m really not sure on whether “pseudo-multimember-gzip” & co. are the right names for the test files, but I don’t think there’s a specific term for this very situation. 😄
I’m also not sure whether the
ctx->strm_.avail_in >= GZIP_MIN_HEADER_SIZE
check innode_zlib.cc
doesn’t open the possibility of another edge case, namely that there is a new gzip member starting, but not enough bytes have been read into the internal buffer. But that is very likely not related to #5852, since I assume it would result in truncated output rather than an error.