From 471284f51b3e89eac74af038332052b99a3e2298 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 14 Nov 2024 11:47:49 +0100 Subject: [PATCH] [api-minor] Disable `ImageDecoder` usage by default in Chromium browsers Given that there are multiple issues with `ImageDecoder` in Chromium browsers, affecting both BMP and JPEG images, for now we (by default) disable that functionality there to avoid problems. This also means that we can remove the previously added, and separate, `isChrome` API-option. --- src/core/evaluator.js | 1 - src/core/image_resizer.js | 6 +----- src/display/api.js | 30 ++++++++++++++++++------------ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 3fe20d2fa1ca3..0bb73f602946e 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -85,7 +85,6 @@ const DefaultPartialEvaluatorOptions = Object.freeze({ isEvalSupported: true, isOffscreenCanvasSupported: false, isImageDecoderSupported: false, - isChrome: false, canvasMaxAreaInBytes: -1, fontExtraProperties: false, useSystemFonts: true, diff --git a/src/core/image_resizer.js b/src/core/image_resizer.js index e5ada29c20b9e..0f80c8f5981da 100644 --- a/src/core/image_resizer.js +++ b/src/core/image_resizer.js @@ -120,17 +120,13 @@ class ImageResizer { static setOptions({ canvasMaxAreaInBytes = -1, - isChrome = false, isImageDecoderSupported = false, }) { if (!this._hasMaxArea) { // Divide by 4 to have the value in pixels. this.MAX_AREA = canvasMaxAreaInBytes >> 2; } - // TODO: remove the isChrome, once Chrome doesn't crash anymore with - // issue6741.pdf. - // https://issues.chromium.org/issues/374807001. - this.#isImageDecoderSupported = isImageDecoderSupported && !isChrome; + this.#isImageDecoderSupported = isImageDecoderSupported; } static _areGoodDims(width, height) { diff --git a/src/display/api.js b/src/display/api.js index 17b5525a78e04..012e45a6373b4 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -181,9 +181,17 @@ const DefaultStandardFontDataFactory = * `ImageDecoder` in the worker. Primarily used to improve performance of * image conversion/rendering. * The default value is `true` in web environments and `false` in Node.js. - * @property {boolean} [isChrome] - Determines if we can use bmp ImageDecoder. - * NOTE: Temporary option until [https://issues.chromium.org/issues/374807001] - * is fixed. + * + * NOTE: Also temporarily disabled in Chromium browsers, until we no longer + * support the affected browser versions, because of various bugs: + * + * - Crashes when using the BMP decoder with huge images, e.g. issue6741.pdf; + * see https://issues.chromium.org/issues/374807001 + * + * - Broken images when using the JPEG decoder with images that have custom + * colour profiles, e.g. GitHub discussion 19030; + * see https://issues.chromium.org/issues/378869810 + * * @property {number} [canvasMaxAreaInBytes] - The integer value is used to * know when an image must be resized (uses `OffscreenCanvas` in the worker). * If it's -1 then a possibly slow algorithm is used to guess the max value. @@ -289,16 +297,15 @@ function getDocument(src = {}) { ? src.isOffscreenCanvasSupported : !isNodeJS; const isImageDecoderSupported = + // eslint-disable-next-line no-nested-ternary typeof src.isImageDecoderSupported === "boolean" ? src.isImageDecoderSupported - : !isNodeJS; - const isChrome = - typeof src.isChrome === "boolean" - ? src.isChrome - : (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) && - !FeatureTest.platform.isFirefox && - typeof window !== "undefined" && - !!window?.chrome; + : // eslint-disable-next-line no-nested-ternary + typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL") + ? true + : typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME") + ? false + : !isNodeJS && (FeatureTest.platform.isFirefox || !globalThis.chrome); const canvasMaxAreaInBytes = Number.isInteger(src.canvasMaxAreaInBytes) ? src.canvasMaxAreaInBytes : -1; @@ -404,7 +411,6 @@ function getDocument(src = {}) { isEvalSupported, isOffscreenCanvasSupported, isImageDecoderSupported, - isChrome, canvasMaxAreaInBytes, fontExtraProperties, useSystemFonts,