From 6509fdb1d6fcf17ee0d0d222868fa35fef784d06 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 1 Feb 2026 18:21:27 +0100 Subject: [PATCH] Assert that `PDFFetchStream` is only used with HTTP(S) URLs Note how `getDocument` checks the protocol, via the `isValidFetchUrl` helper, before attempting to use the `PDFFetchStream` implementation. --- src/display/fetch_stream.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/display/fetch_stream.js b/src/display/fetch_stream.js index cd93c7f18..04525b3ce 100644 --- a/src/display/fetch_stream.js +++ b/src/display/fetch_stream.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { AbortException, warn } from "../shared/util.js"; +import { AbortException, assert, warn } from "../shared/util.js"; import { BasePDFStream, BasePDFStreamRangeReader, @@ -69,8 +69,11 @@ class PDFFetchStream extends BasePDFStream { super(source, PDFFetchStreamReader, PDFFetchStreamRangeReader); const { httpHeaders, url } = source; - this.isHttp = /https?:/.test(url.protocol); - this.headers = createHeaders(this.isHttp, httpHeaders); + assert( + /https?:/.test(url.protocol), + "PDFFetchStream only supports http(s):// URLs." + ); + this.headers = createHeaders(/* isHttp = */ true, httpHeaders); } } @@ -108,7 +111,7 @@ class PDFFetchStreamReader extends BasePDFStreamReader { const { allowRangeRequests, suggestedLength } = validateRangeRequestCapabilities({ responseHeaders, - isHttp: stream.isHttp, + isHttp: true, rangeChunkSize, disableRange, });