Skip to content

compress/flate: reader is not RFC1951 compliant #11030

@dsnet

Description

@dsnet

Running the following produces an error:

package main

import "bytes"
import "compress/flate"

func main() {
    b := bytes.NewBuffer([]byte{
        0x05, 0xc0, 0x07, 0x06, 0x00, 0x00, 0x00, 0x80, 0x40, 0x0f, 0xff, 0x37, 0xa0, 0xca,
    })
    r := flate.NewReader(b)
    _, err := r.Read(nil)
    if err != nil {
        panic(err)
    }
}

The byte slice above represents a single valid DEFLATE block compressed with a dynamic huffman tree, consisting of 257 literal/length codes and 1 distance codes. It should decompresses to nothing.

In the last byte (0xCA), the bit sequence (with LSB on left) is 01010011. The 11 at the end is the EOM marker in DEFLATE; the 0 to the left of that is the single code used for the distance tree.

According to RFC1951 section 3.2.7, it says the following:

One distance code of zero bits means that there are no distance codes used at all (the data is all literals).

As can be seen above, the tree section terminates immediately with an EOM marker (11) and never uses the distance codes. Thus, this should properly decompress.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions