You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, the file is a single page PDF, without any text whatsoever. For my purpose, it doesn't matter, all I need is some return, even if empty.
I've located the loop to be happening at this function bellow:
// Page returns the page for the given page number.
// Page numbers are indexed starting at 1, not 0.
// If the page is not found, Page returns a Page with p.V.IsNull().
func (r *Reader) Page(num int) Page {
num-- // now 0-indexed
page := r.Trailer().Key("Root").Key("Pages")
Search:
for page.Key("Type").Name() == "Pages" {
count := int(page.Key("Count").Int64())
if count < num {
return Page{}
}
kids := page.Key("Kids")
for i := 0; i < kids.Len(); i++ {
kid := kids.Index(i)
if kid.Key("Type").Name() == "Pages" {
c := int(kid.Key("Count").Int64())
if num < c {
page = kid
continue Search
}
num -= c
continue
}
if kid.Key("Type").Name() == "Page" {
if num == 0 {
return Page{kid}
}
num--
}
}
}
return Page{}
}
I have a PDF (which unfortunately I am not allowed to share) that causes an infinite loop in the Page() function.
Basically, none of the two if checks in the kid handling return true and the outer loop just keeps repeating
I'm not a go developer and have no idea about the inner workings of the PDF format, so I don't know how to address this.
Here are two screenshots from the debugger showing the state within the function:
PS I realize that this is probably a problem with the PDF, but I would prefer an error instead of an infinite loop.
The text was updated successfully, but these errors were encountered: