diff --git a/fuzz/CMakeLists.txt b/fuzz/CMakeLists.txt index efa71528..73ecced1 100644 --- a/fuzz/CMakeLists.txt +++ b/fuzz/CMakeLists.txt @@ -114,6 +114,7 @@ set(CORPUS_OTHER 65681.fuzz 65773.fuzz 65777.fuzz + 68377.fuzz ) set(CORPUS_DIR ${CMAKE_CURRENT_BINARY_DIR}/qpdf_corpus) diff --git a/fuzz/qpdf_extra/68377.fuzz b/fuzz/qpdf_extra/68377.fuzz new file mode 100644 index 00000000..61ce0e22 Binary files /dev/null and b/fuzz/qpdf_extra/68377.fuzz differ diff --git a/fuzz/qtest/fuzz.test b/fuzz/qtest/fuzz.test index 7235140d..3ba93156 100644 --- a/fuzz/qtest/fuzz.test +++ b/fuzz/qtest/fuzz.test @@ -21,7 +21,7 @@ my @fuzzers = ( ['pngpredictor' => 1], ['runlength' => 6], ['tiffpredictor' => 2], - ['qpdf' => 56], # increment when adding new files + ['qpdf' => 57], # increment when adding new files ); my $n_tests = 0; diff --git a/libqpdf/QPDF_optimization.cc b/libqpdf/QPDF_optimization.cc index 9f423a3a..75615436 100644 --- a/libqpdf/QPDF_optimization.cc +++ b/libqpdf/QPDF_optimization.cc @@ -416,22 +416,26 @@ QPDF::filterCompressedObjects(QPDFWriter::ObjTable const& obj) ObjUser const& ou = i1.first; // Loop over objects. for (auto const& og: i1.second) { - if (auto const& i2 = obj[og].object_stream; i2 <= 0) { - t_obj_user_to_objects[ou].insert(og); - } else { - t_obj_user_to_objects[ou].insert(QPDFObjGen(i2, 0)); + if (obj.contains(og)) { + if (auto const& i2 = obj[og].object_stream; i2 <= 0) { + t_obj_user_to_objects[ou].insert(og); + } else { + t_obj_user_to_objects[ou].insert(QPDFObjGen(i2, 0)); + } } } } for (auto const& i1: m->object_to_obj_users) { QPDFObjGen const& og = i1.first; - // Loop over obj_users. - for (auto const& ou: i1.second) { - if (auto i2 = obj[og].object_stream; i2 <= 0) { - t_object_to_obj_users[og].insert(ou); - } else { - t_object_to_obj_users[QPDFObjGen(i2, 0)].insert(ou); + if (obj.contains(og)) { + // Loop over obj_users. + for (auto const& ou: i1.second) { + if (auto i2 = obj[og].object_stream; i2 <= 0) { + t_object_to_obj_users[og].insert(ou); + } else { + t_object_to_obj_users[QPDFObjGen(i2, 0)].insert(ou); + } } } } diff --git a/libqpdf/qpdf/ObjTable.hh b/libqpdf/qpdf/ObjTable.hh index 1f0f8a2b..84b51b78 100644 --- a/libqpdf/qpdf/ObjTable.hh +++ b/libqpdf/qpdf/ObjTable.hh @@ -62,6 +62,12 @@ class ObjTable: public std::vector return idx < std::vector::size() || sparse_elements.count(idx); } + inline bool + contains(QPDFObjGen og) const + { + return contains(static_cast(og.getObj())); + } + inline bool contains(QPDFObjectHandle oh) const {