From af2a71aa2c0ab7a441cb4210295e3912800df9d0 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 10 Dec 2021 15:14:26 -0500 Subject: Handle bitstream overflow errors more gracefully (fixes #581) * Make it a runtime error, not a logic error * Include additional information * Capture it properly in checkLinearization --- libqpdf/QPDF_linearization.cc | 6 ++++-- libqpdf/bits.icc | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index 49593f81..56e42f29 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -71,9 +71,11 @@ QPDF::checkLinearization() readLinearizationData(); result = checkLinearizationInternal(); } - catch (QPDFExc& e) + catch (std::runtime_error& e) { - *this->m->err_stream << e.what() << std::endl; + *this->m->err_stream + << "WARNING: error encountered while checking linearization data: " + << e.what() << std::endl; } return result; } diff --git a/libqpdf/bits.icc b/libqpdf/bits.icc index 1cbbebcc..3fb9dfa1 100644 --- a/libqpdf/bits.icc +++ b/libqpdf/bits.icc @@ -6,6 +6,7 @@ #include #include #include +#include // These functions may be run at places where the function call // overhead from test coverage testing would be too high. Therefore, @@ -28,7 +29,10 @@ read_bits(unsigned char const*& p, size_t& bit_offset, if (bits_wanted > bits_available) { - throw std::length_error("overflow reading bit stream"); + throw std::runtime_error( + "overflow reading bit stream: wanted = " + + QUtil::uint_to_string(bits_wanted) + "; available = " + + QUtil::uint_to_string(bits_available)); } if (bits_wanted > 32) { -- cgit v1.2.3-54-g00ecf