Skip to content

Commit

Permalink
Fix two crashers detected by go-fuzz (fixes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Oct 23, 2015
1 parent 97001d3 commit 22d79fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion decompress.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (in *reader) ReadAppend(out *[]byte, n int) {
n -= m
if len(in.cur) == 0 {
in.Rebuffer()
if len(in.cur) == 0 {
in.Err = io.EOF
return
}
}
}
return
Expand Down Expand Up @@ -122,8 +126,8 @@ func copyMatch(out *[]byte, m_pos int, n int) {
m_pos++
}
} else {
// fmt.Println("copy match:", len(*out), m_pos, m_pos+n)
*out = append(*out, (*out)[m_pos:m_pos+n]...)
// fmt.Println("copy match:", string((*out)[m_pos:m_pos+n]))
}
}

Expand Down Expand Up @@ -252,6 +256,10 @@ match:
m_pos -= t >> 2
ip = in.ReadU8()
m_pos -= int(ip) << 2
if m_pos < 0 {
err = LookBehindUnderrun
return
}
// fmt.Println("m_pos tX", m_pos)
copyMatch(&out, m_pos, 2)
goto match_done
Expand Down
14 changes: 14 additions & 0 deletions decompress_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package lzo

import (
"strings"
"testing"
)

func TestDecompCrasher1(t *testing.T) {
Decompress1X(strings.NewReader("\x00"), 0, 0)
}

func TestDecompCrasher2(t *testing.T) {
Decompress1X(strings.NewReader("\x00\x030000000000000000000000\x01\x000\x000"), 0, 0)
}

0 comments on commit 22d79fd

Please sign in to comment.