Skip to content

Commit

Permalink
Reproduce broken legacy lz4 writer
Browse files Browse the repository at this point in the history
First generate a large input file as
  dd if=/dev/urandom of=testdata/bzImage_lz4_isolated bs=64M count=1

then run the test:
  go test -v -run TestWriterLegacy

You'll see error message from lz4 tool:
 "Stream followed by undecodable data at position 8"

Issue pierrec#156
  • Loading branch information
anatol committed Feb 12, 2022
1 parent f9f4ce2 commit e6f5e6f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"os"
"os/exec"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -279,6 +280,23 @@ func TestWriterLegacy(t *testing.T) {
t.Fatal(err)
}

// write to filesystem for further checking
tmp, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmp.Name())
if _, err := tmp.Write(out.Bytes()); err != nil {
t.Fatal(err)
}

cmd := exec.Command("lz4", "--test", tmp.Name())
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
t.Fatal(err)
}

out2 := new(bytes.Buffer)
zr := lz4.NewReader(out)
if _, err := io.Copy(out2, zr); err != nil {
Expand Down

0 comments on commit e6f5e6f

Please sign in to comment.