Merge pull request #14304 from Snuffleupagus/huge-XRef-entry
Ensure that `ChunkedStream` won't attempt to request data *beyond* the document size (issue 14303)
This commit is contained in:
commit
973932321e
@ -107,6 +107,9 @@ class ChunkedStream extends Stream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const chunk = Math.floor(pos / this.chunkSize);
|
const chunk = Math.floor(pos / this.chunkSize);
|
||||||
|
if (chunk > this.numChunks) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (chunk === this.lastSuccessfulEnsureByteChunk) {
|
if (chunk === this.lastSuccessfulEnsureByteChunk) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -125,9 +128,14 @@ class ChunkedStream extends Stream {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chunkSize = this.chunkSize;
|
const beginChunk = Math.floor(begin / this.chunkSize);
|
||||||
const beginChunk = Math.floor(begin / chunkSize);
|
if (beginChunk > this.numChunks) {
|
||||||
const endChunk = Math.floor((end - 1) / chunkSize) + 1;
|
return;
|
||||||
|
}
|
||||||
|
const endChunk = Math.min(
|
||||||
|
Math.floor((end - 1) / this.chunkSize) + 1,
|
||||||
|
this.numChunks
|
||||||
|
);
|
||||||
for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
|
for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
|
||||||
if (!this._loadedChunks.has(chunk)) {
|
if (!this._loadedChunks.has(chunk)) {
|
||||||
throw new MissingDataException(begin, end);
|
throw new MissingDataException(begin, end);
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -487,3 +487,4 @@
|
|||||||
!secHandler.pdf
|
!secHandler.pdf
|
||||||
!rc_annotation.pdf
|
!rc_annotation.pdf
|
||||||
!issue14267.pdf
|
!issue14267.pdf
|
||||||
|
!PDFBOX-4352-0.pdf
|
||||||
|
BIN
test/pdfs/PDFBOX-4352-0.pdf
Normal file
BIN
test/pdfs/PDFBOX-4352-0.pdf
Normal file
Binary file not shown.
@ -443,6 +443,21 @@ describe("api", function () {
|
|||||||
|
|
||||||
await Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]);
|
await Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("creates pdf doc from PDF file with bad XRef table", async function () {
|
||||||
|
// A corrupt PDF file, where the XRef table have (some) bogus entries.
|
||||||
|
const loadingTask = getDocument(
|
||||||
|
buildGetDocumentParams("PDFBOX-4352-0.pdf", {
|
||||||
|
rangeChunkSize: 100,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||||
|
|
||||||
|
const pdfDocument = await loadingTask.promise;
|
||||||
|
expect(pdfDocument.numPages).toEqual(1);
|
||||||
|
|
||||||
|
await loadingTask.destroy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("PDFWorker", function () {
|
describe("PDFWorker", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user