forked from cucy/unipdf1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzz_test.go
71 lines (55 loc) · 1.65 KB
/
fuzz_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
package model
import (
"testing"
"github.com/unidoc/unipdf/v3/core"
)
// Test for an endless recursive loop in
// func (this *PdfReader) buildPageList(node *PdfIndirectObject, parent *PdfIndirectObject) error
func TestFuzzReaderBuildPageLoop(t *testing.T) {
/*
The problem is when there are Pages entries pointing forward and backward (illegal), causing endless
recursive looping.
Example problem data:
3 0 obj
<< /Type /Pages /MediaBox [0 0 595 842] /Count 2 /Kids [ 2 0 R 12 0 R ] >>
endobj
2 0 obj
<< /Type /Pages
/Kids [3 0 R]
/Count 1
/MediaBox [0 0 300 144]
>>
endobj
12 0 obj
<<
/Type /Page
/Parent 3 0 R
/Resources 15 0 R
/Contents 13 0 R
/MediaBox [0 0 595 842]
>>
endobj
*/
pageDict := core.MakeDict()
pageDict.Set("Type", core.MakeName("Pages"))
page := core.MakeIndirectObject(pageDict)
pagesDict := core.MakeDict()
pages := core.MakeIndirectObject(pagesDict)
pagesDict.Set("Type", core.MakeName("Pages"))
pagesDict.Set("Kids", core.MakeArray(page))
pageDict.Set("Kids", core.MakeArray(pages))
// Make a dummy reader to test
dummyPdfReader := PdfReader{}
dummyPdfReader.traversed = map[core.PdfObject]struct{}{}
dummyPdfReader.modelManager = newModelManager()
traversedPageNodes := map[core.PdfObject]struct{}{}
err := dummyPdfReader.buildPageList(pages, nil, traversedPageNodes)
// Current behavior is to avoid the recursive endless loop and simply return nil. Logs a debug message.
if err != nil {
t.Errorf("Fail: %v", err)
}
}