FInd functionality recursion exceeds javascript stack size limitations for large pdf files

RESOLVED FIXED in Firefox 29



PDF Viewer
4 years ago
4 years ago


(Reporter: Karl, Assigned: Karl)


25 Branch
Firefox 29
Windows 7

Firefox Tracking Flags

(Not tracked)


(Whiteboard: [pdfjs-c-ux][pdfjs-d-text-search][pdfjs-f-fixed-upsteam]


(1 attachment)

1.36 MB, application/pdf


4 years ago
Created attachment 8360887 [details]

Steps to Reproduce:
1. Open the attached pdf (2001SimplePages.pdf) using the FF pdf viewer, which is a large number of pages text-only pdf file that only has page numbers for each page. (Note this bug can be duplicated using many pdfs found in the wild, but they are enormous in size, one is the house affordable health care act at, and Intel makes such large pdf files for various processor manuals. Interestingly, with just page numbers and only text this is a very large pdf, although much smaller than it would be with content.)
2. In the find box enter the number string "2000".
3. Wait until the page number 2000 is found and highlighted (can take awhile). 
4. Press the next button (down caret).

What happens:
The find functionality hangs at step 4 showing the swirling busy gif image continuously.

What should happen:
The message that the find wrapped around to the beginning of the file should appear and the same page "2000" should be highlighted. The busy indicator should halt almost immediately.

Further Information:
The following console message occurred (using a version of pdf.js used in one of the FF 25 beta builds)
* Call to xpconnect wrapped JSObject produced this error:  *
[Exception... "'[JavaScript Error: "too much recursion" {file: "resource://pdf.j
s/web/viewer.js" line: 871}]' when calling method: [nsIDOMEventListener::handleE
vent]"  nsresult: "0x80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)"  loc
ation: "native frame :: <unknown filename> :: <TOP_LEVEL> :: line 0"  data: yes]


This console error output identifies the function nextPageMatch (at line 871 in that version) which reads:
The matchesReady function is a local function of nextPageMatch, that in some circumstances calls its parent function nextPageMatch where it reads:
While this two-step recursion can only build a stack with two frames for each page of the document, since pdf documents have an unbounded number of pages this can result in an unbounded linear (multiple of two js stack frames per page) stack size and the result is that the recursion is halted by the runtime for such a large pdf and unique find string—throwing an exception. This exception causes a js promise for the find functionality to fail silently, and then the find functionality sits indefinitely in a pending state. While the bugs are distinct and the fixes do not overlap in the code, this bug can appear to be the same or similar to Bug 916876. It is not clear to me whether Bug 916876 has been fixed already by recent work identified in a pdf.js irc conversation, I will figure that out after this bug has been processed. For this bug I already have working code (distinct from my possibly unneeded fix for Bug 916876) that unravels the unbounded recursion into an iteration, and I will isolate just that fix into a pull request shortly. BTW, the iterative implementation executes considerably faster.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
Reproduced on latest Nightly (20140112004002), set as New.
Ever confirmed: true

Comment 2

4 years ago
I placed a pull-request at that fixes this bug in pdf.js.


4 years ago
Blocks: 950073
Whiteboard: [triage] [defect] p=0


4 years ago
Priority: -- → P3
Whiteboard: [triage] [defect] p=0 → [pdfjs-c-ux][pdfjs-d-text-search]


4 years ago
Whiteboard: [pdfjs-c-ux][pdfjs-d-text-search] → [pdfjs-c-ux][pdfjs-d-text-search][pdfjs-f-fixed-upsteam]
Depends on: 965861
Fixed on trunk by bug 965861.
Last Resolved: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 29
Assignee: nobody → karlden


4 years ago
No longer blocks: 950073
You need to log in before you can comment on or make changes to this bug.