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

RESOLVED FIXED in Firefox 29

Status

()

Firefox
PDF Viewer
P3
normal
RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: Karl, Assigned: Karl)

Tracking

25 Branch
Firefox 29
x86_64
Windows 7
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [pdfjs-c-ux][pdfjs-d-text-search][pdfjs-f-fixed-upsteam] https://github.com/mozilla/pdf.js/pull/4131)

Attachments

(1 attachment)

1.36 MB, application/pdf
Details
(Assignee)

Description

4 years ago
Created attachment 8360887 [details]
2001SimplePages.pdf

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  http://housedocs.house.gov/rules/health/111_ahcaa.pdf, 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:
    matchesReady(pageMatches[pageIdx]);
The matchesReady function is a local function of nextPageMatch, that in some circumstances calls its parent function nextPageMatch where it reads:
        this.nextPageMatch();.
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.
Status: UNCONFIRMED → NEW
Ever confirmed: true
(Assignee)

Comment 2

4 years ago
I placed a pull-request at https://github.com/mozilla/pdf.js/pull/4131 that fixes this bug in pdf.js.

Updated

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

Updated

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

Updated

4 years ago
Whiteboard: [pdfjs-c-ux][pdfjs-d-text-search] → [pdfjs-c-ux][pdfjs-d-text-search][pdfjs-f-fixed-upsteam] https://github.com/mozilla/pdf.js/pull/4131
Depends on: 965861
Fixed on trunk by bug 965861.
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 29
Assignee: nobody → karlden

Updated

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