mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Abort parsing when the XRef /W-array contain bogus entries (issue 14303)
For this particular PDF document, we have `/W [1 2 166666666666666666666666666]` which obviously makes no sense. While this patch makes no attempt at actually validating the entries in the /W-array, we'll now simply abort all processing when the end of the PDF document has been reached (thus preventing hanging the browser). Please note that this patch doesn't enable the PDF document to be loaded/rendered, but at least it fails "correctly" now. Fixes one of the issues listed in issue 14303, namely the `REDHAT-1531897-0.pdf`document.
This commit is contained in:
parent
a2c380ccb3
commit
ca8d2bdce4
4 changed files with 36 additions and 3 deletions
|
@ -323,17 +323,29 @@ class XRef {
|
|||
offset = 0,
|
||||
generation = 0;
|
||||
for (j = 0; j < typeFieldWidth; ++j) {
|
||||
type = (type << 8) | stream.getByte();
|
||||
const typeByte = stream.getByte();
|
||||
if (typeByte === -1) {
|
||||
throw new FormatError("Invalid XRef byteWidths 'type'.");
|
||||
}
|
||||
type = (type << 8) | typeByte;
|
||||
}
|
||||
// if type field is absent, its default value is 1
|
||||
if (typeFieldWidth === 0) {
|
||||
type = 1;
|
||||
}
|
||||
for (j = 0; j < offsetFieldWidth; ++j) {
|
||||
offset = (offset << 8) | stream.getByte();
|
||||
const offsetByte = stream.getByte();
|
||||
if (offsetByte === -1) {
|
||||
throw new FormatError("Invalid XRef byteWidths 'offset'.");
|
||||
}
|
||||
offset = (offset << 8) | offsetByte;
|
||||
}
|
||||
for (j = 0; j < generationFieldWidth; ++j) {
|
||||
generation = (generation << 8) | stream.getByte();
|
||||
const generationByte = stream.getByte();
|
||||
if (generationByte === -1) {
|
||||
throw new FormatError("Invalid XRef byteWidths 'generation'.");
|
||||
}
|
||||
generation = (generation << 8) | generationByte;
|
||||
}
|
||||
const entry = {};
|
||||
entry.offset = offset;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue