1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +02:00

Prevent errors, in SimpleXMLParser.onEndElement, when the stack has already been completely parsed (issue 10410)

The error was triggered for a particular set of metadata, where an end tag was encountered without the corresponding begin tag being present in the data.
(The patch also fixes a minor oversight, from a recent PR, in the `SimpleDOMNode.nextSibling` method.)
This commit is contained in:
Jonas Jenwald 2019-01-04 11:37:44 +01:00
parent b39ec7af96
commit e8f4b47d59
2 changed files with 29 additions and 1 deletions

View file

@ -287,6 +287,9 @@ class SimpleDOMNode {
return undefined;
}
const index = childNodes.indexOf(this);
if (index === -1) {
return undefined;
}
return childNodes[index + 1];
}
@ -364,8 +367,11 @@ class SimpleXMLParser extends XMLParserBase {
}
onEndElement(name) {
this._currentFragment = this._stack.pop();
this._currentFragment = this._stack.pop() || [];
const lastElement = this._currentFragment[this._currentFragment.length - 1];
if (!lastElement) {
return;
}
for (let i = 0, ii = lastElement.childNodes.length; i < ii; i++) {
lastElement.childNodes[i].parentNode = lastElement;
}