From 5e5daca407e42562c08fba62364f1593c697c9e7 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 2 May 2021 21:23:12 +0200 Subject: [PATCH] Remove unnecessary `MissingDataException` check from `getHeaderBlock` It shouldn't be possible for the `getBytes`-call to throw a `MissingDataException`, since all resources are loaded *before* e.g. font-parsing ever starts; see https://github.com/mozilla/pdf.js/blob/f0817015bd0b5b3dd498427df85c564e9eb08603/src/core/object_loader.js#L111-L126 Furthermore, even if we'd *somehow* re-throw a `MissingDataException` here that still won't help considering where the `Type1Font`-instance is created. Note how in the `Font`-constructor we simply catch any errors and fallback to a standard font, which means that a `MissingDataException` would just lead to rendering errors anyway; see https://github.com/mozilla/pdf.js/blob/f0817015bd0b5b3dd498427df85c564e9eb08603/src/core/fonts.js#L648-L691 All-in-all, it's not possible for a `MissingDataException` to be thrown in `getHeaderBlock` and this code-path can thus be removed. --- src/core/type1_font.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/core/type1_font.js b/src/core/type1_font.js index bcb46bc82..bde53e9a1 100644 --- a/src/core/type1_font.js +++ b/src/core/type1_font.js @@ -24,8 +24,8 @@ import { CFFStrings, CFFTopDict, } from "./cff_parser.js"; -import { isWhiteSpace, MissingDataException } from "./core_utils.js"; import { SEAC_ANALYSIS_ENABLED, type1FontGlyphMapping } from "./fonts_utils.js"; +import { isWhiteSpace } from "./core_utils.js"; import { Stream } from "./stream.js"; import { Type1Parser } from "./type1_parser.js"; import { warn } from "../shared/util.js"; @@ -68,9 +68,6 @@ function getHeaderBlock(stream, suggestedLength) { headerBytes = stream.getBytes(suggestedLength); headerBytesLength = headerBytes.length; } catch (ex) { - if (ex instanceof MissingDataException) { - throw ex; - } // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array // cannot hold the result of `getBytes`, and fallback to simply checking // the entire stream (fixes issue3928.pdf).