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