Everything a decompressing reader produces is copied without a limit
What it finds
io.Copy(dst, gzipReader) or io.ReadAll(zr): a few kilobytes of compressed input can expand to gigabytes, so input from outside fills the disk or the memory of the process. io.CopyN or an io.LimitReader around the reader stops at a size the program is prepared for.
The reader must be a variable declared as the first result of NewReader of compress/gzip, compress/zlib, compress/flate or compress/bzip2, and it must be passed directly to io.Copy, io.ReadAll or ioutil.ReadAll, all resolved through the imports.
From the rule's source, unbounded_decompression.rs.
package p import ( "compress/gzip" "io") func f(dst io.Writer, r io.Reader) error { zr, err := gzip.NewReader(r) if err != nil { return err } if _, err := io.Copy(dst, zr); err != nil {tx0 reports: all that zr decompresses is read without a limit return err } _, err = io.CopyN(dst, zr, 1<<20) return err} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go:unbounded-decompression" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:unbounded-decompression] reason="..."tx0 explain tx0/go:unbounded-decompression shows the same in the terminal. Found a false positive? Report it.