Skip to content

ungzipping buffer with trailing garbage throws error #7502

Description

@horpto

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:

varzlib=require('zlib')// from test-zlib-from-gzip-with-trailing-garbage.jsbufOk=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 Errorconsole.log("bufOk:",zlib.gunzipSync(bufOk).toString());// will raise Error('incorrect header check')console.log("bufWrong:",zlib.gunzipSync(bufWrong).toString());

Also live example:

varreq=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

Metadata

Metadata

Assignees

No one assigned

    Labels

    zlibIssues and PRs related to the zlib subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions