Skip to content

Commit 22d79fd

Browse files
committed
Fix two crashers detected by go-fuzz (fixes #1)
1 parent 97001d3 commit 22d79fd

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

decompress.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func (in *reader) ReadAppend(out *[]byte, n int) {
7575
n -= m
7676
if len(in.cur) == 0 {
7777
in.Rebuffer()
78+
if len(in.cur) == 0 {
79+
in.Err = io.EOF
80+
return
81+
}
7882
}
7983
}
8084
return
@@ -122,8 +126,8 @@ func copyMatch(out *[]byte, m_pos int, n int) {
122126
m_pos++
123127
}
124128
} else {
129+
// fmt.Println("copy match:", len(*out), m_pos, m_pos+n)
125130
*out = append(*out, (*out)[m_pos:m_pos+n]...)
126-
// fmt.Println("copy match:", string((*out)[m_pos:m_pos+n]))
127131
}
128132
}
129133

@@ -252,6 +256,10 @@ match:
252256
m_pos -= t >> 2
253257
ip = in.ReadU8()
254258
m_pos -= int(ip) << 2
259+
if m_pos < 0 {
260+
err = LookBehindUnderrun
261+
return
262+
}
255263
// fmt.Println("m_pos tX", m_pos)
256264
copyMatch(&out, m_pos, 2)
257265
goto match_done

decompress_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package lzo
2+
3+
import (
4+
"strings"
5+
"testing"
6+
)
7+
8+
func TestDecompCrasher1(t *testing.T) {
9+
Decompress1X(strings.NewReader("\x00"), 0, 0)
10+
}
11+
12+
func TestDecompCrasher2(t *testing.T) {
13+
Decompress1X(strings.NewReader("\x00\x030000000000000000000000\x01\x000\x000"), 0, 0)
14+
}

0 commit comments

Comments
 (0)