klauspost / pgzip

Go parallel gzip (de)compression
MIT License
1.12k stars 77 forks source link

Pgzip does not correctly error on truncated files (hangs indefinitely) #13

Closed tjj5036 closed 7 years ago

tjj5036 commented 7 years ago

If you create a file like so:

$ for i in `seq 1 100`; do echo "ASDFASDFASDFASDFASDF" >> foobar; done
$ gunzip foobar
$ head -c 30 foobar.gz > foobar2.gz

And try and extract it with the following:

package main

import (
  gzip "github.com/klauspost/pgzip" 
  "io" 
  "os" 
) 

func main() { 
  badDataReader, err := os.Open("foobar2.gz") 
  if err != nil { 
    os.Exit(1) 
  } 

  gzipReader, err := gzip.NewReader(badDataReader) 
  if err != nil { 
    os.Exit(1) 
  } 

  _, err = io.Copy(os.Stdout, gzipReader)
  if err != nil {
    os.Exit(2)
  }
}

pgzip will indefinitely hang, however using compress/gzip will correctly error out.