From c280ccd33b3d85dbd2e5a3edd4fbeeded65a2288 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 20 Sep 2020 06:08:15 -0400 Subject: [PATCH] Clear stream errors in FileStore::MaxRetrievable (GH #968) --- files.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/files.cpp b/files.cpp index 2d05e03f..22af7097 100644 --- a/files.cpp +++ b/files.cpp @@ -65,10 +65,19 @@ lword FileStore::MaxRetrievable() const if (!m_stream) return 0; + // Clear error bits due to seekg(). Also see + // https://github.com/weidai11/cryptopp/pull/968 std::streampos current = m_stream->tellg(); std::streampos end = m_stream->seekg(0, std::ios::end).tellg(); m_stream->clear(); m_stream->seekg(current); + m_stream->clear(); + + // Return max for a non-seekable stream + // https://www.cplusplus.com/reference/istream/istream/tellg/ + if (end == static_cast(-1)) + return LWORD_MAX; + return end-current; }