-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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 gzip member header/input buffer boundary issue #5883
Changes from all commits
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 |
---|---|---|
|
@@ -7,9 +7,12 @@ const zlib = require('zlib'); | |
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const abcEncoded = zlib.gzipSync('abc'); | ||
const defEncoded = zlib.gzipSync('def'); | ||
|
||
const data = Buffer.concat([ | ||
zlib.gzipSync('abc'), | ||
zlib.gzipSync('def') | ||
abcEncoded, | ||
defEncoded | ||
]); | ||
|
||
assert.equal(zlib.gunzipSync(data).toString(), 'abcdef'); | ||
|
@@ -38,3 +41,26 @@ fs.createReadStream(pmmFileGz) | |
assert.deepStrictEqual(Buffer.concat(pmmResultBuffers), pmmExpected, | ||
'result should match original random garbage'); | ||
})); | ||
|
||
// test that the next gzip member can wrap around the input buffer boundary | ||
[0, 1, 2, 3, 4, defEncoded.length].forEach((offset) => { | ||
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. @kthelgason I think testing for The first 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. of course, you're absolutely right. |
||
const resultBuffers = []; | ||
|
||
const unzip = zlib.createGunzip() | ||
.on('error', (err) => { | ||
assert.ifError(err); | ||
}) | ||
.on('data', (data) => resultBuffers.push(data)) | ||
.on('finish', common.mustCall(() => { | ||
assert.strictEqual(Buffer.concat(resultBuffers).toString(), 'abcdef', | ||
`result should match original input (offset = ${offset})`); | ||
})); | ||
|
||
// first write: write "abc" + the first bytes of "def" | ||
unzip.write(Buffer.concat([ | ||
abcEncoded, defEncoded.slice(0, offset) | ||
])); | ||
|
||
// write remaining bytes of "def" | ||
unzip.end(defEncoded.slice(offset)); | ||
}); |
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.
These
define
s are unused now right?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.
Yep, but #5884 would start using them again, so I’d leave them in unless it gets decided that that should not get landed.