From 7fac12a60ed352646e8c85cc4c557095979f5a80 Mon Sep 17 00:00:00 2001
From: Mark Rogers <mark.rogers@powermapper.com>
Date: Fri, 13 Apr 2018 14:27:47 +0100
Subject: [PATCH] PoDoFo: m_offsets.resize() can throw std::length_error and
 other implementation-specifc exceptions in addition to std::bad_alloc

---
 Electrum/Mapper/Libs/podofo/src/base/PdfParser.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/Electrum/Mapper/Libs/podofo/src/base/PdfParser.cpp b/Electrum/Mapper/Libs/podofo/src/base/PdfParser.cpp
index e8823cddf..c6aeb47e5 100644
--- a/Electrum/Mapper/Libs/podofo/src/base/PdfParser.cpp
+++ b/Electrum/Mapper/Libs/podofo/src/base/PdfParser.cpp
@@ -791,7 +791,13 @@ void PdfParser::ReadXRefSubsection( pdf_int64 & nFirstObject, pdf_int64 & nNumOb
                 m_nNumObjects = nFirstObject + nNumObjects;
                 m_offsets.resize(nFirstObject+nNumObjects);
 #endif // _WIN32
-            } catch (std::bad_alloc &) {
+            } catch (std::exception &) {
+                // If m_nNumObjects*sizeof(TXRefEntry) > std::numeric_limits<size_t>::max() then
+                // resize() throws std::length_error, for smaller allocations that fail it may throw
+                // std::bad_alloc (implementation-dependent). "20.5.5.12 Restrictions on exception 
+                // handling" in the C++ Standard says any function that throws an exception is allowed 
+                // to throw implementation-defined exceptions derived the base type (std::exception)
+                // so we need to catch all std::exceptions here
                 PODOFO_RAISE_ERROR( ePdfError_OutOfMemory );
             }
         }
-- 
2.15.1

