mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-26 13:48:55 +08:00
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
/*
|
|
* 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)
|
|
}
|
|
|
|
}
|