90a931
From 4f478daa6a9734b8f269a6586bdce2909844bb6f Mon Sep 17 00:00:00 2001
90a931
From: Albert Astals Cid <aacid@kde.org>
90a931
Date: Wed, 23 Dec 2020 23:52:58 +0100
90a931
Subject: Fix opening files by some generators that are a bit broken
90a931
90a931
But Adobe opens it and it's easy to fix
90a931
90a931
diff --git a/poppler/XRef.cc b/poppler/XRef.cc
90a931
index 66d3f04a..c36c747a 100644
90a931
--- a/poppler/XRef.cc
90a931
+++ b/poppler/XRef.cc
90a931
@@ -45,6 +45,7 @@
90a931
 #include <cctype>
90a931
 #include <climits>
90a931
 #include <cfloat>
90a931
+#include <limits>
90a931
 #include "goo/gfile.h"
90a931
 #include "goo/gmem.h"
90a931
 #include "Object.h"
90a931
@@ -793,8 +794,13 @@ bool XRef::readXRefStreamSection(Stream *xrefStr, const int *w, int first, int n
90a931
             gen = (gen << 8) + c;
90a931
         }
90a931
         if (gen > INT_MAX) {
90a931
-            error(errSyntaxError, -1, "Gen inside xref table too large (bigger than INT_MAX)");
90a931
-            return false;
90a931
+            if (i == 0 && gen == std::numeric_limits<uint32_t>::max()) {
90a931
+                // workaround broken generators
90a931
+                gen = 65535;
90a931
+            } else {
90a931
+                error(errSyntaxError, -1, "Gen inside xref table too large (bigger than INT_MAX)");
90a931
+                return false;
90a931
+            }
90a931
         }
90a931
         if (entries[i].offset == -1) {
90a931
             switch (type) {