1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

Ensure that ChunkedStream won't attempt to request data *beyond* the document size (issue 14303)

This bug was surprisingly difficult to track down, since it didn't just depend on range-requests being used but also on how quickly the document was loaded. To even be able to reproduce this locally, I had to use a very small `rangeChunkSize`-value (note the unit-test).

The cause of this bug is a bogus entry in the XRef-table, causing us to attempt to request data from *beyond* the actual document size and thus getting into an infinite loop.

Fixes *one* of the issues listed in issue 14303, namely the `PDFBOX-4352-0.pdf` document.
This commit is contained in:
Jonas Jenwald 2021-11-24 18:55:28 +01:00
parent 5e2aec7dd7
commit ae4f1ae3e7
4 changed files with 28 additions and 4 deletions

View file

@ -107,6 +107,9 @@ class ChunkedStream extends Stream {
}
const chunk = Math.floor(pos / this.chunkSize);
if (chunk > this.numChunks) {
return;
}
if (chunk === this.lastSuccessfulEnsureByteChunk) {
return;
}
@ -125,9 +128,14 @@ class ChunkedStream extends Stream {
return;
}
const chunkSize = this.chunkSize;
const beginChunk = Math.floor(begin / chunkSize);
const endChunk = Math.floor((end - 1) / chunkSize) + 1;
const beginChunk = Math.floor(begin / this.chunkSize);
if (beginChunk > this.numChunks) {
return;
}
const endChunk = Math.min(
Math.floor((end - 1) / this.chunkSize) + 1,
this.numChunks
);
for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
if (!this._loadedChunks.has(chunk)) {
throw new MissingDataException(begin, end);