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

PDFjs.getMetadata() - XML parse bug #10395

Closed
dhollenbeck opened this issue Dec 29, 2018 · 2 comments
Closed

PDFjs.getMetadata() - XML parse bug #10395

dhollenbeck opened this issue Dec 29, 2018 · 2 comments
Labels

Comments

@dhollenbeck
Copy link

When getMetadata() is invoked on a specific PDF file, which I can not provide:

var loader = pdfjs.getDocument(source);
loader.promise.then(function getDocumentSuccess(pdf) {
  pdf.getMetadata().then(function () {}).catch(...);
});

I get the following error:

(node:7452) TypeError: Cannot read property '0' of undefined
    at SimpleDOMNode.get (...\node_modules\pdfjs-dist\build\pdf.js:14097:29)
    at Metadata._parse (...\node_modules\pdfjs-dist\build\pdf.js:13740:19)
    at new Metadata (...\node_modules\pdfjs-dist\build\pdf.js:13698:12)
    at ...\pdfjs-dist\build\pdf.js:9421:34
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

I believe the following line of code is the line with the bug:

get firstChild() {
return this.childNodes[0];
}

Obviously, this.childNodes could be undefined as is the case with my pdf file. It is being invoked via an automatic property get function above:

rdf = rdf.firstChild;

The offending XML document has the structure of:

{ documentElement: SimpleDOMNode { nodeName: '#text', nodeValue: '' } }
@timvandermeij
Copy link
Contributor

@dhollenbeck Would it be possible to provide a test case without sensitive data here as well like you did for the other issue? Either a file or the XML itself is fine. This would allow us to add a unit test for this so we can avoid regressions in the future, and allow us to verify the fix.

@dhollenbeck
Copy link
Author

Absolutely, @timvandermeij
toissue.pdf

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

No branches or pull requests

2 participants