-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
zlib: fix raw inflate with custom dictionary #8512
Conversation
case INFLATERAW: | ||
ctx->err_ = inflateInit2(&ctx->strm_, ctx->windowBits_); | ||
ctx->env()->isolate() | ||
->AdjustAmountOfExternalAllocatedMemory(kInflateContextSize); |
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.
Just a suggestion, but if you want to avoid duplicating this, you can just turn the break;
statement above into if (ctx->mode_ != INFLATERAW) break;
and leave the case INFLATERAW:
where it is.
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.
Even better: Could this be moved into SetDictionary
?
This looks awesome so far, thanks for putting this together! |
Thanks for the feedback! I'll address the points you raised tonight. |
@addaleax I moved the dictionary initialization into SetDictionary like you suggested as it was much cleaner, thanks! Since the extra test file I added was nearly identical to the existing dictionary test file I fixed the same issues you raised in the new one in the old one as well. Do you think I should merge these two files since they are so similar, or should they be kept separate? |
inflate.end(); | ||
}); | ||
|
||
inflate.on('end', function() { |
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.
Could you wrap all of these functions which will be called exactly once in a common.mustCall()
? (You can do that in test-zlib-dictionary.js
too, if you want)
That’s your call, if you think it’s easy to merge them together, why not? This looks good to me (LGTM) with Here’s a CI run: https://ci.nodejs.org/job/node-test-commit/5048/ |
@addaleax Merged the files and added |
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.
LGTM with CI: https://ci.nodejs.org/job/node-test-commit/5105/
deflate.on('data', common.mustCall(function(chunk) { | ||
if (doneReset) | ||
inflate.write(chunk); | ||
}, 2)); |
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.
I’d say common.mustCall()
for data
callbacks is optional, I don’t think we’re currently guaranteeing anything about the exact chunking or want to do that (I think this is okay if the CI is green with it included, so it’s your call).
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.
Fair point, seems like a leaky implementation detail. I removed the mustCall
s from non-assertion functions, as if the assertion passes the others are guaranteed to have run, and it will fail if the assertion isn't called.
Pushed new (final?) changeset without |
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.
CI: https://ci.nodejs.org/job/node-test-commit/5141/
This looks great, I’ll try to merge this by tomorrow unless somebody else wants to review/objects.
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.
LGTM
Eek, merge conflicts… @thusoy can you rebase this? Apparently one of thea general cleanup PRs of the tests here got in the way of your own cleanup… sorry for that! |
Moves inflateSetDictionary right after inflateInit2 when mode is INFLATERAW, since without the wrapper in appears zlib won't return Z_NEED_DICT as it would otherwise, and will thus attempt inflating without the dictionary, leading to an error. Fixes: nodejs#8507
Uses const where possible, removes inaccurate comments, prefers strictEqual where possible, ensures functions with assertions are called and enures the inflater has correct encoding set.
@addaleax Yup, done. |
That was fast! Still LGTM. New CI: https://ci.nodejs.org/job/node-test-commit/5189/ I’m going to land this if it’s green. |
Moves inflateSetDictionary right after inflateInit2 when mode is INFLATERAW, since without the wrapper in appears zlib won't return Z_NEED_DICT as it would otherwise, and will thus attempt inflating without the dictionary, leading to an error. Fixes: #8507 PR-URL: #8512 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
Uses const where possible, removes inaccurate comments, prefers strictEqual where possible, ensures functions with assertions are called and enures the inflater has correct encoding set. PR-URL: #8512 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
Great stuff, thanks @addaleax! Happy to contribute! |
Moves inflateSetDictionary right after inflateInit2 when mode is INFLATERAW, since without the wrapper in appears zlib won't return Z_NEED_DICT as it would otherwise, and will thus attempt inflating without the dictionary, leading to an error. Fixes: #8507 PR-URL: #8512 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
Uses const where possible, removes inaccurate comments, prefers strictEqual where possible, ensures functions with assertions are called and enures the inflater has correct encoding set. PR-URL: #8512 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
backport? |
@thealphanerd If that is a yes/no question, yes. :) @thusoy Would you be up for backporting this change to the v4.x release line? There are some conflicts in the test files that seem to need resolving. The usual process for that would be checking out the |
@addaleax Thanks for the heads-up on the process. I might be able to that, but will probably be a couple of days before I have time. Consider me on the case for now. |
This is just roughly tested, but I just ported the change from nodejs/node#8512, or at least attempted to. Before, when trying to inflateRaw (or inflate({raw:true});) with a custom dictionary, you would get 'invalid distance too far back'. This no longer seems to happen, so I think I fixed it.
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
zlib
Description of change
Moves inflateSetDictionary right after inflateInit2 when mode is
INFLATERAW, since without the wrapper in appears zlib won't return
Z_NEED_DICT as it would otherwise, and will thus attempt inflating
without the dictionary, leading to an error.
Closes #8507.