Skip to content

Commit 5d96569

Browse files
committed
add another test for infinite loop found with fuzzing and fix it
1 parent c1390b0 commit 5d96569

File tree

2 files changed

+12
-47
lines changed

2 files changed

+12
-47
lines changed

fuzz_crashes_test.go

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ func TestCrash1(t *testing.T) {
2828
}
2929
}
3030

31-
func TestInfinite1(t *testing.T) {
32-
test := "[[[[[[\n\t: ]]]]]]\n\n: " + "\n\n:(()"
31+
func parseWithShortTimeout(t *testing.T, test string) {
3332
c := make(chan bool, 1)
3433
go func() {
3534
Parse([]byte(test), nil)
@@ -38,54 +37,20 @@ func TestInfinite1(t *testing.T) {
3837
select {
3938
case <-c:
4039
case <-time.After(2 * time.Second):
41-
t.Fatalf("timed out")
40+
t.Fatalf("timed out parsing %#v\n", test)
4241
}
4342
}
43+
func TestInfinite1(t *testing.T) {
44+
test := "[[[[[[\n\t: ]]]]]]\n\n: " + "\n\n:(()"
45+
parseWithShortTimeout(t, test)
46+
}
4447

45-
/*
46-
program hanged (timeout 10 seconds)
47-
48-
SIGABRT: abort
49-
PC=0x10bf96a m=0 sigcode=0
50-
51-
goroutine 1 [running]:
52-
github.com/gomarkdown/markdown/ast.LastChild(0x120ea60, 0xc42014b170, 0x120eb20, 0xc42005be00)
53-
ast/node.go:349 +0x2a fp=0xc42049dbd0 sp=0xc42049dba0 pc=0x10bf96a
54-
github.com/gomarkdown/markdown/parser.endsWithBlankLine(0x120ea60, 0xc42014b170, 0x0)
55-
parser/block.go:1202 +0x6b fp=0xc42049dc00 sp=0xc42049dbd0 pc=0x10fea0b
56-
github.com/gomarkdown/markdown/parser.finalizeList.func3(0xc42049dc88, 0xc42044c000)
57-
parser/block.go:1226 +0x4f fp=0xc42049dc28 sp=0xc42049dc00 pc=0x1112cbf
58-
github.com/gomarkdown/markdown/parser.finalizeList(0xc42011c3f0)
59-
parser/block.go:1226 +0x11a fp=0xc42049dcb8 sp=0xc42049dc28 pc=0x10febea
60-
github.com/gomarkdown/markdown/parser.(*Parser).list(0xc42045b200, 0x12e600e, 0x7, 0x1ffff2, 0x16, 0x0)
61-
parser/block.go:1187 +0x27b fp=0xc42049dd30 sp=0xc42049dcb8 pc=0x10fe90b
62-
github.com/gomarkdown/markdown/parser.(*Parser).paragraph(0xc42045b200, 0x12e6000, 0x15, 0x200000, 0x0)
63-
parser/block.go:1482 +0xfd4 fp=0xc42049de00 sp=0xc42049dd30 pc=0x11016d4
64-
github.com/gomarkdown/markdown/parser.(*Parser).block(0xc42045b200, 0x12e6000, 0x15, 0x200000)
65-
parser/block.go:247 +0x6b8 fp=0xc42049de40 sp=0xc42049de00 pc=0x10f64e8
66-
github.com/gomarkdown/markdown/parser.(*Parser).Parse(0xc42045b200, 0x12e6000, 0x15, 0x200000, 0x8, 0x5a71671a)
67-
parser/parser.go:241 +0x65 fp=0xc42049de78 sp=0xc42049de40 pc=0x110d295
68-
github.com/gomarkdown/markdown.Parse(0x12e6000, 0x15, 0x200000, 0x0, 0x1289f8c0, 0xa23912f)
69-
markdown.go:46 +0x9a fp=0xc42049deb8 sp=0xc42049de78 pc=0x1118caa
70-
github.com/gomarkdown/markdown.Fuzz(0x12e6000, 0x15, 0x200000, 0x3)
71-
fuzz.go:7 +0x60 fp=0xc42049def8 sp=0xc42049deb8 pc=0x1118bf0
72-
go-fuzz-dep.Main(0x11606d8)
73-
/var/folders/v_/ksw1dqvd59v790zk2wqf_t_80000gn/T/go-fuzz-build351448921/goroot/src/go-fuzz-dep/main.go:49 +0xad fp=0xc42049df68 sp=0xc42049def8 pc=0x1065a4d
74-
main.main()
75-
go.fuzz.main/main.go:10 +0x2d fp=0xc42049df80 sp=0xc42049df68 pc=0x1118dad
76-
runtime.main()
77-
*/
7848
func TestInfinite2(t *testing.T) {
7949
test := ":\x00\x00\x00\x01V\n>* \x00\x80e\n\t* \n\n:\t"
50+
parseWithShortTimeout(t, test)
51+
}
8052

81-
c := make(chan bool, 1)
82-
go func() {
83-
Parse([]byte(test), nil)
84-
c <- true
85-
}()
86-
select {
87-
case <-c:
88-
case <-time.After(2 * time.Second):
89-
t.Fatalf("timed out")
90-
}
53+
func TestInfinite3(t *testing.T) {
54+
test := "\xa2 \n\t: \n: "
55+
parseWithShortTimeout(t, test)
9156
}

parser/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ func (p *Parser) paragraph(data []byte) int {
15481548
if p.extensions&DefinitionLists != 0 {
15491549
if p.dliPrefix(current) != 0 {
15501550
ret := p.list(data[prev:], ast.ListTypeDefinition)
1551-
return ret
1551+
return ret + prev
15521552
}
15531553
}
15541554

0 commit comments

Comments
 (0)