From d22eb3591e3fb34e74a67a06d11e8532ba081150 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 12 Nov 2022 16:11:56 +0100 Subject: [PATCH] Change the `assert` in `Parser.findDefaultInlineStreamEnd` to a non-PRODUCTION one Given that this `assert` is only intended to catch any implementation bugs in our code, and not actually to validate the PDF data directly[1], we can avoid making this function call unconditionally. --- [1] In those cases, for example a `FormatError` should have been thrown instead. --- src/core/parser.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/parser.js b/src/core/parser.js index 92816879e..118c42633 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -203,7 +203,12 @@ class Parser { } else if (state === 1) { state = ch === I ? 2 : 0; } else { - assert(state === 2, "findDefaultInlineStreamEnd - invalid state."); + if ( + typeof PDFJSDev === "undefined" || + PDFJSDev.test("!PRODUCTION || TESTING") + ) { + assert(state === 2, "findDefaultInlineStreamEnd - invalid state."); + } if (ch === SPACE || ch === LF || ch === CR) { maybeEIPos = stream.pos; // Let's check that the next `n` bytes are ASCII... just to be sure.