Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

huff0: fix handling errors in Decompress1X asm #604

Merged
merged 1 commit into from May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions huff0/_generate/gen.go
Expand Up @@ -495,6 +495,8 @@ func (d decompress1x) generateProcedure(name string) {
MOVQ(I64(-1), tmp)
Store(tmp, ctx.Field("decoded"))
}

RET()
}

func (d decompress1x) decompress(id int, br *bitReader, peekBits, dt reg.GPVirtual, out reg.Register) {
Expand Down
2 changes: 2 additions & 0 deletions huff0/decompress_amd64.s
Expand Up @@ -765,6 +765,7 @@ error_max_decoded_size_exeeded:
MOVQ ctx+0(FP), AX
MOVQ $-1, CX
MOVQ CX, 40(AX)
RET

// func decompress1x_main_loop_bmi2(ctx *decompress1xContext)
// Requires: BMI2
Expand Down Expand Up @@ -861,3 +862,4 @@ error_max_decoded_size_exeeded:
MOVQ ctx+0(FP), AX
MOVQ $-1, CX
MOVQ CX, 40(AX)
RET
40 changes: 40 additions & 0 deletions huff0/decompress_test.go
Expand Up @@ -3,7 +3,10 @@ package huff0
import (
"bytes"
"fmt"
"io/ioutil"
"testing"

"github.com/klauspost/compress/zip"
)

func TestDecompress1X(t *testing.T) {
Expand Down Expand Up @@ -96,6 +99,43 @@ func TestDecompress1X(t *testing.T) {
}
}

func TestDecompress1XRegression(t *testing.T) {
data, err := ioutil.ReadFile("testdata/decompress1x_regression.zip")
if err != nil {
t.Fatal(err)
}
zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data)))
if err != nil {
t.Fatal(err)
}
for _, tt := range zr.File {
if tt.UncompressedSize64 == 0 {
continue
}
rc, err := tt.Open()
if err != nil {
t.Fatal(err)
}
data, err := ioutil.ReadAll(rc)
if err != nil {
t.Fatal(err)
}

t.Run(tt.Name, func(t *testing.T) {
s, rem, err := ReadTable(data, nil)
if err != nil {
t.Fatal(err)
}
_, err = s.Decompress1X(rem)
if err == nil {
t.Fatal("expected error to be returned")
}

t.Logf("returned error: %s", err)
})
}
}

func TestDecompress4X(t *testing.T) {
for _, test := range testfiles {
t.Run(test.name, func(t *testing.T) {
Expand Down
Binary file added huff0/testdata/decompress1x_regression.zip
Binary file not shown.