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