Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] TypeError: Cannot read properties of undefined (reading 'slice') at at Function.Util_normalizeRect [as normalizeRect] #298

Merged
merged 7 commits into from Mar 26, 2023

Conversation

zzeleznick
Copy link
Contributor

Description

This PR adds upstream fixes from pdf.js in mozilla/pdf.js#14784 and mozilla/pdf.js#6239, respectively, that fixes an issue I saw when trying to parse a PDF with malformed annotations. The key change was validating the rectangle was valid – and you can remove the improved intersection code if desired.

Example File:

Land-Sector-and-Removals-Guidance-Pilot-Testing-and-Review-Draft.pdf

Trace

TypeError: Cannot read properties of undefined (reading 'slice')
    at Function.Util_normalizeRect [as normalizeRect] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:509:18)
    at new Annotation (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:3531:22)
    at Function.Annotation_fromRef [as fromRef] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:3728:22)
    at Page.get annotations [as annotations] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:4437:37)
    at LocalPdfManager_ensure [as ensure] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:32520:22)
    at Page_getOperatorList [as getOperatorList] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:4365:43)
    at Object.eval [as onResolve] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:27414:14)
    at Object.runHandlers (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:855:35)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

{
  message: "Cannot read properties of undefined (reading 'slice')",
  stack: "TypeError: Cannot read properties of undefined (reading 'slice')\n" +
    '    at Function.Util_normalizeRect [as normalizeRect] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:509:18)\n' +
    '    at new Annotation (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:3531:22)\n' +
    '    at Function.Annotation_fromRef [as fromRef] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:3728:22)\n' +
    '    at Page.get annotations [as annotations] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:4437:37)\n' +
    '    at LocalPdfManager_ensure [as ensure] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:32520:22)\n' +
    '    at Page_getOperatorList [as getOperatorList] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:4365:43)\n' +
    '    at Object.eval [as onResolve] (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:27414:14)\n' +
    '    at Object.runHandlers (eval at <anonymous> (file:///Users/zeleznick/Dev/pdf2json/lib/pdf.js:66:1), <anonymous>:855:35)\n' +
    '    at listOnTimeout (node:internal/timers:559:17)\n' +
    '    at processTimers (node:internal/timers:502:7)'
}
Error: Page 13: Cannot read properties of undefined (reading 'slice')

@modesty modesty merged commit 989a6c1 into modesty:master Mar 26, 2023
@modesty
Copy link
Owner

modesty commented Mar 26, 2023

nice work, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants