From d22eb3591e3fb34e74a67a06d11e8532ba081150 Mon Sep 17 00:00:00 2001
From: Jonas Jenwald <jonas.jenwald@gmail.com>
Date: Sat, 12 Nov 2022 16:11:56 +0100
Subject: [PATCH 1/2] 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.

From a1d48e3651e39530fa4695a5293a9aa08091eb27 Mon Sep 17 00:00:00 2001
From: Jonas Jenwald <jonas.jenwald@gmail.com>
Date: Sat, 12 Nov 2022 16:20:19 +0100
Subject: [PATCH 2/2] Add a *linked* test-case for issue 2618

Given that this PDF document is an interesting test-case for performance reasons, w.r.t. inline image caching, it probably can't hurt to add it to the test-suite to make it more readily available.
Considering the contents of that PDF document I'm not sure if we can include it directly in the repository, hence why a *linked* test-case was choosen here.
---
 test/pdfs/issue2618.pdf.link | 1 +
 test/test_manifest.json      | 8 ++++++++
 2 files changed, 9 insertions(+)
 create mode 100644 test/pdfs/issue2618.pdf.link

diff --git a/test/pdfs/issue2618.pdf.link b/test/pdfs/issue2618.pdf.link
new file mode 100644
index 000000000..e15b631d5
--- /dev/null
+++ b/test/pdfs/issue2618.pdf.link
@@ -0,0 +1 @@
+https://github.com/mozilla/pdf.js/files/9983741/issue2618.pdf
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 26ef711ba..ad74e9133 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -3047,6 +3047,14 @@
        "rounds": 1,
        "type": "eq"
     },
+    {  "id": "issue2618",
+       "file": "pdfs/issue2618.pdf",
+       "md5": "2c554a99a52288ca1a44a422eeafb8fb",
+       "rounds": 1,
+       "lastPage": 1,
+       "link": true,
+       "type": "eq"
+    },
     {  "id": "issue2642",
       "file": "pdfs/issue2642.pdf",
       "md5": "b6679861fdce3bbab0c1fa51bb7f5077",