1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Ensure that a missing/invalid "Content-Range" header is handled in PDFNetworkStream (issue 19075)

In the event that the "Content-Range" header is missing/invalid, loading will now be aborted rather than hanging indefinitely.
This commit is contained in:
Jonas Jenwald 2024-11-27 12:33:39 +01:00
parent e04b62ba2d
commit 2661d0623b
3 changed files with 64 additions and 7 deletions

View file

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { assert, stringToBytes } from "../shared/util.js";
import { assert, stringToBytes, warn } from "../shared/util.js";
import {
createHeaders,
createResponseStatusError,
@ -161,10 +161,15 @@ class NetworkManager {
if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
const rangeHeader = xhr.getResponseHeader("Content-Range");
const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
pendingRequest.onDone({
begin: parseInt(matches[1], 10),
chunk,
});
if (matches) {
pendingRequest.onDone({
begin: parseInt(matches[1], 10),
chunk,
});
} else {
warn(`Missing or invalid "Content-Range" header.`);
pendingRequest.onError?.(0);
}
} else if (chunk) {
pendingRequest.onDone({
begin: 0,