39ecc3
From 81044c64b9ed9a10ae82a28bac753060bdfdac74 Mon Sep 17 00:00:00 2001
39ecc3
From: Albert Astals Cid <aacid@kde.org>
39ecc3
Date: Tue, 15 Mar 2022 15:14:32 +0100
39ecc3
Subject: Hints::readTables: bail out if we run out of file when reading
39ecc3
39ecc3
Fixes #1230
39ecc3
39ecc3
diff --git a/poppler/Hints.cc b/poppler/Hints.cc
39ecc3
index 79f04088..4707e1c6 100644
39ecc3
--- a/poppler/Hints.cc
39ecc3
+++ b/poppler/Hints.cc
39ecc3
@@ -5,7 +5,7 @@
39ecc3
 // This file is licensed under the GPLv2 or later
39ecc3
 //
39ecc3
 // Copyright 2010, 2012 Hib Eris <hib@hiberis.nl>
39ecc3
-// Copyright 2010, 2011, 2013, 2014, 2016-2019 Albert Astals Cid <aacid@kde.org>
39ecc3
+// Copyright 2010, 2011, 2013, 2014, 2016-2019, 2021, 2022 Albert Astals Cid <aacid@kde.org>
39ecc3
 // Copyright 2010, 2013 Pino Toscano <pino@kde.org>
39ecc3
 // Copyright 2013 Adrian Johnson <ajohnson@redneon.com>
39ecc3
 // Copyright 2014 Fabio D'Urso <fabiodurso@hotmail.it>
39ecc3
@@ -189,21 +189,31 @@ void Hints::readTables(BaseStream *str, Linearization *linearization, XRef *xref
39ecc3
     char *p = &buf[0];
39ecc3
 
39ecc3
     if (hintsOffset && hintsLength) {
39ecc3
-        Stream *s = str->makeSubStream(hintsOffset, false, hintsLength, Object(objNull));
39ecc3
+        std::unique_ptr<Stream> s(str->makeSubStream(hintsOffset, false, hintsLength, Object(objNull)));
39ecc3
         s->reset();
39ecc3
         for (unsigned int i = 0; i < hintsLength; i++) {
39ecc3
-            *p++ = s->getChar();
39ecc3
+            const int c = s->getChar();
39ecc3
+            if (unlikely(c == EOF)) {
39ecc3
+                error(errSyntaxWarning, -1, "Found EOF while reading hints");
39ecc3
+                ok = false;
39ecc3
+                return;
39ecc3
+            }
39ecc3
+            *p++ = c;
39ecc3
         }
39ecc3
-        delete s;
39ecc3
     }
39ecc3
 
39ecc3
     if (hintsOffset2 && hintsLength2) {
39ecc3
-        Stream *s = str->makeSubStream(hintsOffset2, false, hintsLength2, Object(objNull));
39ecc3
+        std::unique_ptr<Stream> s(str->makeSubStream(hintsOffset2, false, hintsLength2, Object(objNull)));
39ecc3
         s->reset();
39ecc3
         for (unsigned int i = 0; i < hintsLength2; i++) {
39ecc3
-            *p++ = s->getChar();
39ecc3
+            const int c = s->getChar();
39ecc3
+            if (unlikely(c == EOF)) {
39ecc3
+                error(errSyntaxWarning, -1, "Found EOF while reading hints2");
39ecc3
+                ok = false;
39ecc3
+                return;
39ecc3
+            }
39ecc3
+            *p++ = c;
39ecc3
         }
39ecc3
-        delete s;
39ecc3
     }
39ecc3
 
39ecc3
     MemStream *memStream = new MemStream(&buf[0], 0, bufLength, Object(objNull));