Commit 20edfb3f9100735187734523514d256b52a85035
1 parent
7f3b05dd
In QPDF::damagedPDF change input parameter to InputSource&
Showing
2 changed files
with
16 additions
and
23 deletions
include/qpdf/QPDF.hh
| @@ -1088,14 +1088,11 @@ class QPDF | @@ -1088,14 +1088,11 @@ class QPDF | ||
| 1088 | qpdf_offset_t end_before_space, | 1088 | qpdf_offset_t end_before_space, |
| 1089 | qpdf_offset_t end_after_space); | 1089 | qpdf_offset_t end_after_space); |
| 1090 | static QPDFExc damagedPDF( | 1090 | static QPDFExc damagedPDF( |
| 1091 | - std::shared_ptr<InputSource> const& input, | 1091 | + InputSource& input, |
| 1092 | std::string const& object, | 1092 | std::string const& object, |
| 1093 | qpdf_offset_t offset, | 1093 | qpdf_offset_t offset, |
| 1094 | std::string const& message); | 1094 | std::string const& message); |
| 1095 | - QPDFExc damagedPDF( | ||
| 1096 | - std::shared_ptr<InputSource> const& input, | ||
| 1097 | - qpdf_offset_t offset, | ||
| 1098 | - std::string const& message); | 1095 | + QPDFExc damagedPDF(InputSource& input, qpdf_offset_t offset, std::string const& message); |
| 1099 | QPDFExc damagedPDF(std::string const& object, qpdf_offset_t offset, std::string const& message); | 1096 | QPDFExc damagedPDF(std::string const& object, qpdf_offset_t offset, std::string const& message); |
| 1100 | QPDFExc damagedPDF(std::string const& object, std::string const& message); | 1097 | QPDFExc damagedPDF(std::string const& object, std::string const& message); |
| 1101 | QPDFExc damagedPDF(qpdf_offset_t offset, std::string const& message); | 1098 | QPDFExc damagedPDF(qpdf_offset_t offset, std::string const& message); |
libqpdf/QPDF.cc
| @@ -1493,7 +1493,7 @@ QPDF::readObject(std::string const& description, QPDFObjGen og) | @@ -1493,7 +1493,7 @@ QPDF::readObject(std::string const& description, QPDFObjGen og) | ||
| 1493 | if (empty) { | 1493 | if (empty) { |
| 1494 | // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in | 1494 | // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in |
| 1495 | // actual PDF files and Adobe Reader appears to ignore them. | 1495 | // actual PDF files and Adobe Reader appears to ignore them. |
| 1496 | - warn(damagedPDF(m->file, m->file->getLastOffset(), "empty object treated as null")); | 1496 | + warn(damagedPDF(*m->file, m->file->getLastOffset(), "empty object treated as null")); |
| 1497 | return object; | 1497 | return object; |
| 1498 | } | 1498 | } |
| 1499 | auto token = readToken(m->file); | 1499 | auto token = readToken(m->file); |
| @@ -1613,7 +1613,7 @@ QPDF::readObjectInStream(std::shared_ptr<InputSource>& input, int obj) | @@ -1613,7 +1613,7 @@ QPDF::readObjectInStream(std::shared_ptr<InputSource>& input, int obj) | ||
| 1613 | if (empty) { | 1613 | if (empty) { |
| 1614 | // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in | 1614 | // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in |
| 1615 | // actual PDF files and Adobe Reader appears to ignore them. | 1615 | // actual PDF files and Adobe Reader appears to ignore them. |
| 1616 | - warn(damagedPDF(input, input->getLastOffset(), "empty object treated as null")); | 1616 | + warn(damagedPDF(*input, input->getLastOffset(), "empty object treated as null")); |
| 1617 | } | 1617 | } |
| 1618 | return object; | 1618 | return object; |
| 1619 | } | 1619 | } |
| @@ -1635,7 +1635,7 @@ QPDF::recoverStreamLength( | @@ -1635,7 +1635,7 @@ QPDF::recoverStreamLength( | ||
| 1635 | std::shared_ptr<InputSource> input, QPDFObjGen const& og, qpdf_offset_t stream_offset) | 1635 | std::shared_ptr<InputSource> input, QPDFObjGen const& og, qpdf_offset_t stream_offset) |
| 1636 | { | 1636 | { |
| 1637 | // Try to reconstruct stream length by looking for endstream or endobj | 1637 | // Try to reconstruct stream length by looking for endstream or endobj |
| 1638 | - warn(damagedPDF(input, stream_offset, "attempting to recover stream length")); | 1638 | + warn(damagedPDF(*input, stream_offset, "attempting to recover stream length")); |
| 1639 | 1639 | ||
| 1640 | PatternFinder ef(*this, &QPDF::findEndstream); | 1640 | PatternFinder ef(*this, &QPDF::findEndstream); |
| 1641 | size_t length = 0; | 1641 | size_t length = 0; |
| @@ -1674,10 +1674,10 @@ QPDF::recoverStreamLength( | @@ -1674,10 +1674,10 @@ QPDF::recoverStreamLength( | ||
| 1674 | 1674 | ||
| 1675 | if (length == 0) { | 1675 | if (length == 0) { |
| 1676 | warn(damagedPDF( | 1676 | warn(damagedPDF( |
| 1677 | - input, stream_offset, "unable to recover stream data; treating stream as empty")); | 1677 | + *input, stream_offset, "unable to recover stream data; treating stream as empty")); |
| 1678 | } else { | 1678 | } else { |
| 1679 | - warn( | ||
| 1680 | - damagedPDF(input, stream_offset, "recovered stream length: " + std::to_string(length))); | 1679 | + warn(damagedPDF( |
| 1680 | + *input, stream_offset, "recovered stream length: " + std::to_string(length))); | ||
| 1681 | } | 1681 | } |
| 1682 | 1682 | ||
| 1683 | QTC::TC("qpdf", "QPDF recovered stream length"); | 1683 | QTC::TC("qpdf", "QPDF recovered stream length"); |
| @@ -1958,7 +1958,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1958,7 +1958,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1958 | QPDFTokenizer::Token toffset = readToken(input); | 1958 | QPDFTokenizer::Token toffset = readToken(input); |
| 1959 | if (!(tnum.isInteger() && toffset.isInteger())) { | 1959 | if (!(tnum.isInteger() && toffset.isInteger())) { |
| 1960 | throw damagedPDF( | 1960 | throw damagedPDF( |
| 1961 | - input, | 1961 | + *input, |
| 1962 | m->last_object_description, | 1962 | m->last_object_description, |
| 1963 | input->getLastOffset(), | 1963 | input->getLastOffset(), |
| 1964 | "expected integer in object stream header"); | 1964 | "expected integer in object stream header"); |
| @@ -1972,7 +1972,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1972,7 +1972,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1972 | if (num == obj_stream_number) { | 1972 | if (num == obj_stream_number) { |
| 1973 | QTC::TC("qpdf", "QPDF ignore self-referential object stream"); | 1973 | QTC::TC("qpdf", "QPDF ignore self-referential object stream"); |
| 1974 | warn(damagedPDF( | 1974 | warn(damagedPDF( |
| 1975 | - input, | 1975 | + *input, |
| 1976 | m->last_object_description, | 1976 | m->last_object_description, |
| 1977 | input->getLastOffset(), | 1977 | input->getLastOffset(), |
| 1978 | "object stream claims to contain itself")); | 1978 | "object stream claims to contain itself")); |
| @@ -2726,7 +2726,7 @@ QPDF::pipeStreamData( | @@ -2726,7 +2726,7 @@ QPDF::pipeStreamData( | ||
| 2726 | file->seek(offset, SEEK_SET); | 2726 | file->seek(offset, SEEK_SET); |
| 2727 | auto buf = std::make_unique<char[]>(length); | 2727 | auto buf = std::make_unique<char[]>(length); |
| 2728 | if (auto read = file->read(buf.get(), length); read != length) { | 2728 | if (auto read = file->read(buf.get(), length); read != length) { |
| 2729 | - throw damagedPDF(file, "", offset + toO(read), "unexpected EOF reading stream data"); | 2729 | + throw damagedPDF(*file, "", offset + toO(read), "unexpected EOF reading stream data"); |
| 2730 | } | 2730 | } |
| 2731 | pipeline->write(buf.get(), length); | 2731 | pipeline->write(buf.get(), length); |
| 2732 | attempted_finish = true; | 2732 | attempted_finish = true; |
| @@ -2742,7 +2742,7 @@ QPDF::pipeStreamData( | @@ -2742,7 +2742,7 @@ QPDF::pipeStreamData( | ||
| 2742 | qpdf_for_warning.warn( | 2742 | qpdf_for_warning.warn( |
| 2743 | // line-break | 2743 | // line-break |
| 2744 | damagedPDF( | 2744 | damagedPDF( |
| 2745 | - file, | 2745 | + *file, |
| 2746 | "", | 2746 | "", |
| 2747 | file->getLastOffset(), | 2747 | file->getLastOffset(), |
| 2748 | ("error decoding stream data for object " + og.unparse(' ') + ": " + | 2748 | ("error decoding stream data for object " + og.unparse(' ') + ": " + |
| @@ -2751,7 +2751,7 @@ QPDF::pipeStreamData( | @@ -2751,7 +2751,7 @@ QPDF::pipeStreamData( | ||
| 2751 | qpdf_for_warning.warn( | 2751 | qpdf_for_warning.warn( |
| 2752 | // line-break | 2752 | // line-break |
| 2753 | damagedPDF( | 2753 | damagedPDF( |
| 2754 | - file, | 2754 | + *file, |
| 2755 | "", | 2755 | "", |
| 2756 | file->getLastOffset(), | 2756 | file->getLastOffset(), |
| 2757 | "stream will be re-processed without filtering to avoid data loss")); | 2757 | "stream will be re-processed without filtering to avoid data loss")); |
| @@ -2825,19 +2825,15 @@ QPDF::stopOnError(std::string const& message) | @@ -2825,19 +2825,15 @@ QPDF::stopOnError(std::string const& message) | ||
| 2825 | // Return an exception of type qpdf_e_damaged_pdf. | 2825 | // Return an exception of type qpdf_e_damaged_pdf. |
| 2826 | QPDFExc | 2826 | QPDFExc |
| 2827 | QPDF::damagedPDF( | 2827 | QPDF::damagedPDF( |
| 2828 | - std::shared_ptr<InputSource> const& input, | ||
| 2829 | - std::string const& object, | ||
| 2830 | - qpdf_offset_t offset, | ||
| 2831 | - std::string const& message) | 2828 | + InputSource& input, std::string const& object, qpdf_offset_t offset, std::string const& message) |
| 2832 | { | 2829 | { |
| 2833 | - return {qpdf_e_damaged_pdf, input->getName(), object, offset, message}; | 2830 | + return {qpdf_e_damaged_pdf, input.getName(), object, offset, message}; |
| 2834 | } | 2831 | } |
| 2835 | 2832 | ||
| 2836 | // Return an exception of type qpdf_e_damaged_pdf. The object is taken from | 2833 | // Return an exception of type qpdf_e_damaged_pdf. The object is taken from |
| 2837 | // m->last_object_description. | 2834 | // m->last_object_description. |
| 2838 | QPDFExc | 2835 | QPDFExc |
| 2839 | -QPDF::damagedPDF( | ||
| 2840 | - std::shared_ptr<InputSource> const& input, qpdf_offset_t offset, std::string const& message) | 2836 | +QPDF::damagedPDF(InputSource& input, qpdf_offset_t offset, std::string const& message) |
| 2841 | { | 2837 | { |
| 2842 | return damagedPDF(input, m->last_object_description, offset, message); | 2838 | return damagedPDF(input, m->last_object_description, offset, message); |
| 2843 | } | 2839 | } |