golang/go

archive/tar: slice bounds out of range (3)

dvyukov opened this issue · 5 comments

The following program crashes with a panic:

package main

import (
    "archive/tar"
    "bytes"
    "io"
    "io/ioutil"
)

func main() {
    data := []byte("\x13\x0300\x13\x03-821950\x0096t\x13\x13\x83" +
        "s|\x83s\x1300qw\xe1f\xbb\x03000\x00\x00\x00\x10" +
        "011\x13s\xf410100t\x13\x13\x83s|\x83ss" +
        "\x000\x13s|\x83ss\xf4xS\x13s\xf410100t" +
        "\x13\x13\x83s|\x00ss\xf40\x13s|\x83ss0qS0" +
        "\xd4t0\x1300q0\xf40\x00\x00\x00\x1001\x80\x00\x100" +
        "11\x13s\xf410100t\x1300q\xd4\xe1f\xbb\x03" +
        "\x00\x00\x00\xff\x80\x80\x80\x00\x80\x00\x00\x00\x00\x00j.S\x13\xff\xff" +
        "\xff\x80100txS00t0\x1300qw010" +
        "100t\x13\x13\x83s|\x83ss\xf4xS00t0\x13" +
        "00qw\xe1f\xbb\x03000\x00\x00\x00\x10011\x13s" +
        "\xf410100t\x13\x13\x83s|\x83ss\xf40\x13s|" +
        "\x83s\xf4\xf4xS\x13s\xf410100t\x13\x13\x83s|" +
        "4ss00\x13s|\x83sssx100t0\x130" +
        "0q00\x00\x80\x00\x00\x1001s\xf4100\x0000t" +
        "\x13\x00\x00\x00 \xe1f\xbb\x0304\x00\x00\x00\x10011\x13\xff" +
        "\xff\xff\x80100txS00t0\x1300qw\xe1f" +
        "\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x002\x00\x00\x00\x00" +
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
        "\x00\x00\x00\x00\x001\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
    t := tar.NewReader(bytes.NewReader(data))
    for {
        _, err := t.Next()
        if err != nil {
            return
        }
        io.Copy(ioutil.Discard, t)
    }
}
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
archive/tar.(*sparseFileReader).Read(0xc2080143c0, 0xc208074000, 0x2000, 0x2000, 0x0, 0x0, 0x0)
    src/archive/tar/reader.go:800 +0x2da
archive/tar.(*Reader).Read(0xc208070000, 0xc208074000, 0x2000, 0x2000, 0x0, 0x0, 0x0)
    src/archive/tar/reader.go:735 +0x9d
io/ioutil.devNull.ReadFrom(0x0, 0x7efd372e3298, 0xc208070000, 0x2, 0x0, 0x0)
    src/io/ioutil/ioutil.go:151 +0xa1
io/ioutil.(*devNull).ReadFrom(0xc20800a4a0, 0x7efd372e3298, 0xc208070000, 0xc208041e40, 0x0, 0x0)
    <autogenerated>:9 +0xb4
io.copyBuffer(0x7efd372e31c0, 0xc20800a4a0, 0x7efd372e3298, 0xc208070000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    src/io/io.go:375 +0x183
io.Copy(0x7efd372e31c0, 0xc20800a4a0, 0x7efd372e3298, 0xc208070000, 0x200, 0x0, 0x0)
    src/io/io.go:351 +0x6b
main.main()
    tar.go:43 +0x1df

on commit 8017ace

I believe this was fixed by c2fe4a0.

Still happens on tip. Note that the top frame is different than in other crashes.

Cannot reproduce on master branch (built as of c04813e)

rsc commented

It's too late in the Go 1.5 release process for fuzzer bugs. The chance of hitting any of these is so low that the benefit of the fix is outweighed by the chance of the fix introducing a more serious bug.

Yeah, I probably did not run 'go install archive/tar' after pull. Can't reproduce it on fresh build as well. Closing.