From b44acdb03e89434037f534a3847153d5aa730f51 Mon Sep 17 00:00:00 2001
From: Henry <Henry>
Date: Wed, 18 Feb 2015 08:12:01 +0000
Subject: [PATCH] PtrList: Check for EOF while reading to avoid run-on and
 infinite loop when reading list of dictionaries. Resolves bug-report
 http://www.openfoam.org/mantisbt/view.php?id=1538

---
 src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C b/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C
index b03dcf1fa0..b3728e56ef 100644
--- a/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C
+++ b/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -115,6 +115,17 @@ void Foam::PtrList<T>::read(Istream& is, const INew& inewt)
         )
         {
             is.putBack(lastToken);
+
+            if (is.eof())
+            {
+                FatalIOErrorIn
+                (
+                    "PtrList<T>::read(Istream&, const INew&)",
+                    is
+                )   << "Premature EOF after reading " << lastToken.info()
+                    << exit(FatalIOError);
+            }
+
             sllPtrs.append(inewt(is).ptr());
             is >> lastToken;
         }
-- 
GitLab