ungzipping buffer with trailing garbage throws error #7502
Closed
Description
One site sends a gzipped html page and I try to ungzip page for further processing but zlib throws error incorrect header check
. Error happens due to extra data after gzipped page. Yes, gzipped data is not valid, since have trailing data, but in other hand, browser eat that normally.
Minimal example:
var zlib = require('zlib')
// from test-zlib-from-gzip-with-trailing-garbage.js
bufOk = Buffer.concat([
zlib.gzipSync("abc"),
Buffer(10).fill(0)
]);
bufWrong = Buffer.concat([
zlib.gzipSync("abc"),
Buffer("\n \n\n\n\n \n")
]);
// wil not raise Error
console.log("bufOk:", zlib.gunzipSync(bufOk).toString());
// will raise Error('incorrect header check')
console.log("bufWrong:", zlib.gunzipSync(bufWrong).toString());
Also live example:
var req = require('request')
req.get('http://irsural.ru', {gzip: true}, (err, res, body) => {
if (err != null) {
console.log('Error:', err);
return
}
console.log(body);
});
In other languages (for example, python - requests) I can set windowBits
to 16 + zlib.Z_MAX_WINDOWBITS
but node
strictly restricted windowBits
from 0 to 15 even in addon.
- Version: v6.2.2
- Platform: linux, x86_64
- Subsystem: zlib
Activity