The archive backend passes remote .sqfs bytes straight to the go-diskfs squashfs parser, which does not validate several attacker-controlled superblock and metadata fields. A crafted image can make the parser panic. Recover panics at the go-diskfs boundary and return an "invalid or corrupt squashfs image" error instead. As well as the parse entry points (Read, ReadDir, OpenFile) this wraps the reader returned by Open, since the parser reads file data lazily and can panic long after the image opened successfully. Addresses GHSA-6jcg-q3wp-x2f4.
26 lines
787 B
Go
26 lines
787 B
Go
package squashfs
|
|
|
|
import (
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// panickingReader panics on Read, standing in for the go-diskfs parser
|
|
// hitting an unchecked slice while reading a malformed image.
|
|
type panickingReader struct{}
|
|
|
|
func (panickingReader) Read([]byte) (int, error) { panic("boom") }
|
|
func (panickingReader) Close() error { return nil }
|
|
|
|
// Test that a panic raised while reading file data becomes an error. The
|
|
// parser reads lazily, so an image can open cleanly and only panic here.
|
|
func TestRecoveringReadCloser(t *testing.T) {
|
|
var rc io.ReadCloser = recoveringReadCloser{panickingReader{}}
|
|
|
|
_, err := rc.Read(make([]byte, 16))
|
|
assert.ErrorContains(t, err, "invalid or corrupt squashfs image")
|
|
assert.ErrorContains(t, err, "boom")
|
|
}
|