From f67eab000b36228203343ec98de0bdcc28d47bd5 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Tue, 7 Jan 2014 14:21:54 -0800 Subject: [PATCH] fix(util/serializer): nontermination on corrupted files Signed-off-by: Leonardo de Moura --- src/util/serializer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/util/serializer.cpp b/src/util/serializer.cpp index d6c16fe87..90db9921b 100644 --- a/src/util/serializer.cpp +++ b/src/util/serializer.cpp @@ -27,6 +27,10 @@ void serializer_core::write_int(int i) { #define BIG_BUFFER 1024 +void throw_corrupted_file() { + throw exception("corrupted binary file"); +} + void serializer_core::write_double(double d) { std::ostringstream out; // TODO(Leo): the following code may miss precision. @@ -44,6 +48,8 @@ std::string deserializer_core::read_string() { char c = m_in.get(); if (c == 0) break; + if (c == EOF) + throw_corrupted_file(); r += c; } return r; @@ -70,8 +76,4 @@ double deserializer_core::read_double() { in >> r; return r; } - -void throw_corrupted_file() { - throw exception("corrupted binary file"); -} }