Repository navigation
zlib: fix windowBits validation to allow 0 for decompression mode #19686
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -251,9 +251,20 @@ function Zlib(opts, mode) { | |||||||||
| opts.finishFlush, 'options.finishFlush', | ||||||||||
| Z_NO_FLUSH, Z_BLOCK, Z_FINISH); | ||||||||||
|
|
||||||||||
| windowBits = checkRangesOrGetDefault( | ||||||||||
| opts.windowBits, 'options.windowBits', | ||||||||||
| Z_MIN_WINDOWBITS, Z_MAX_WINDOWBITS, Z_DEFAULT_WINDOWBITS); | ||||||||||
| // windowBits is special. On the compression side, 0 is an invalid value. | ||||||||||
| // But on the decompression side, a value of 0 for windowBits tells zlib | ||||||||||
| // to extract the value from the headers of the compressed stream. | ||||||||||
| if (opts.windowBits === 0 && | ||||||||||
| (mode === INFLATE || | ||||||||||
| mode === GUNZIP || | ||||||||||
| mode === INFLATERAW || | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I picked the list from Lines 541 to 544 in 22f4a35
inflateInit2(). Will remove it from the list.
|
||||||||||
| mode === UNZIP)) { | ||||||||||
| windowBits = 0 | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you run
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whoops. I'm spoiled by standardjs! Will fix. |
||||||||||
| } else { | ||||||||||
| windowBits = checkRangesOrGetDefault( | ||||||||||
| opts.windowBits, 'options.windowBits', | ||||||||||
| Z_MIN_WINDOWBITS, Z_MAX_WINDOWBITS, Z_DEFAULT_WINDOWBITS); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| level = checkRangesOrGetDefault( | ||||||||||
| opts.level, 'options.level', | ||||||||||
|
|
||||||||||
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.
We may actually want to also capture
undefinedhere, so that when decompressing we always go with the header-provided value (instead of the safe maximum) for lower memory usage.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.
excellent idea! How about
opts.windowBits == null || opts.windowBits === 0?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.
@anandsuresh Sounds reasonable to me!