1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Ensure that the response-origin of range requests match the full request (issue 12744)

The following cases are excluded in the patch:
 - The Firefox PDF Viewer, since it has been fixed on the platform side already; please see https://bugzilla.mozilla.org/show_bug.cgi?id=1683940

 - The `PDFNodeStream`-implementation, used in Node.js environments, since after recent changes that code only supports `file://`-URLs.

Also updates the `PDFNetworkStreamFullRequestReader.read`-method to await the headers before returning any data, similar to the implementation in `src/display/fetch_stream.js`.

*Note:* The relevant unit-tests are updated to await the `headersReady` Promise before dispatching range requests, since that's consistent with the actual usage in the `src/`-folder.
This commit is contained in:
Jonas Jenwald 2024-11-10 16:00:38 +01:00
parent 1f6cc85134
commit 6a015588b9
6 changed files with 57 additions and 9 deletions

View file

@ -54,7 +54,7 @@ describe("fetch_stream", function () {
const fullReader = stream.getFullReader();
let isStreamingSupported, isRangeSupported;
const promise = fullReader.headersReady.then(function () {
await fullReader.headersReady.then(function () {
isStreamingSupported = fullReader.isStreamingSupported;
isRangeSupported = fullReader.isRangeSupported;
});
@ -71,7 +71,7 @@ describe("fetch_stream", function () {
});
};
await Promise.all([read(), promise]);
await read();
expect(len).toEqual(pdfLength);
expect(isStreamingSupported).toEqual(true);
@ -90,7 +90,7 @@ describe("fetch_stream", function () {
const fullReader = stream.getFullReader();
let isStreamingSupported, isRangeSupported, fullReaderCancelled;
const promise = fullReader.headersReady.then(function () {
await fullReader.headersReady.then(function () {
isStreamingSupported = fullReader.isStreamingSupported;
isRangeSupported = fullReader.isRangeSupported;
// We shall be able to close full reader without any issue.
@ -121,7 +121,6 @@ describe("fetch_stream", function () {
await Promise.all([
read(rangeReader1, result1),
read(rangeReader2, result2),
promise,
]);
expect(isStreamingSupported).toEqual(true);

View file

@ -31,7 +31,7 @@ describe("network", function () {
const fullReader = stream.getFullReader();
let isStreamingSupported, isRangeSupported;
const promise = fullReader.headersReady.then(function () {
await fullReader.headersReady.then(function () {
isStreamingSupported = fullReader.isStreamingSupported;
isRangeSupported = fullReader.isRangeSupported;
});
@ -49,7 +49,7 @@ describe("network", function () {
});
};
await Promise.all([read(), promise]);
await read();
expect(len).toEqual(pdf1Length);
expect(count).toEqual(1);
@ -72,7 +72,7 @@ describe("network", function () {
const fullReader = stream.getFullReader();
let isStreamingSupported, isRangeSupported, fullReaderCancelled;
const promise = fullReader.headersReady.then(function () {
await fullReader.headersReady.then(function () {
isStreamingSupported = fullReader.isStreamingSupported;
isRangeSupported = fullReader.isRangeSupported;
// we shall be able to close the full reader without issues
@ -107,7 +107,6 @@ describe("network", function () {
await Promise.all([
read(range1Reader, result1),
read(range2Reader, result2),
promise,
]);
expect(result1.value).toEqual(rangeSize);