Skip to content

s2 compression panic: index out of range [0] with length 0 #929

@iamcalledrob

Description

@iamcalledrob

I think this may be a separate issue to #902, so opening another one.

I'm encountering a panic when compressing a specific stream of data with s2. It looks like there may be a missing bounds check when emitting repeat chunks?

panic: runtime error: index out of range [0] with length 0

goroutine 251 [running]:
github.com/klauspost/compress/s2.emitRepeat({0x140009e400b?, 0x0?, 0x0?}, 0x140009e1f78?, 0x0?)
	/Users/rob/go/pkg/mod/github.com/klauspost/compress@v1.17.6/s2/encode_go.go:111 +0x1e0
github.com/klauspost/compress/s2.encodeBlockGo({0x140009e400b, 0x10004, 0x10004}, {0x140009d2008, 0x10000, 0x10007})
	/Users/rob/go/pkg/mod/github.com/klauspost/compress@v1.17.6/s2/encode_all.go:146 +0x938
github.com/klauspost/compress/s2.encodeBlock(...)
	/Users/rob/go/pkg/mod/github.com/klauspost/compress@v1.17.6/s2/encode_go.go:24
github.com/klauspost/compress/s2.(*Writer).encodeBlock(0x140009d2008?, {0x140009e400b?, 0x0?, 0x140003dcee0?}, {0x140009d2008?, 0x103bbf0f4?, 0x1400053e0a0?})
	/Users/rob/go/pkg/mod/github.com/klauspost/compress@v1.17.6/s2/writer.go:457 +0x178
github.com/klauspost/compress/s2.(*Writer).writeFull.func1()
	/Users/rob/go/pkg/mod/github.com/klauspost/compress@v1.17.6/s2/writer.go:599 +0x128
created by github.com/klauspost/compress/s2.(*Writer).writeFull in goroutine 235
	/Users/rob/go/pkg/mod/github.com/klauspost/compress@v1.17.6/s2/writer.go:590 +0x388

The stream in question is 185gb, but this crash occurs fairly early within it, and reproduces every time on arm64 (Darwin, M-series)

I'll look at following up with a more straightforward test case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions