Commit 4660e23262fd3606d0b9ef7db9bcc315783b16e3
Committed by
GitHub
Merge pull request #1128 from m-holger/reconstruct
Tighten checks for invalid indirect references during xref reconstru…
Showing
3 changed files
with
5 additions
and
1 deletions
libqpdf/QPDF.cc
| @@ -1195,6 +1195,10 @@ QPDF::insertFreeXrefEntry(QPDFObjGen og) | @@ -1195,6 +1195,10 @@ QPDF::insertFreeXrefEntry(QPDFObjGen og) | ||
| 1195 | void | 1195 | void |
| 1196 | QPDF::insertReconstructedXrefEntry(int obj, qpdf_offset_t f1, int f2) | 1196 | QPDF::insertReconstructedXrefEntry(int obj, qpdf_offset_t f1, int f2) |
| 1197 | { | 1197 | { |
| 1198 | + if (!(obj > 0 && 0 <= f2 && f2 < 65535)) { | ||
| 1199 | + QTC::TC("qpdf", "QPDF xref overwrite invalid objgen"); | ||
| 1200 | + return; | ||
| 1201 | + } | ||
| 1198 | QPDFObjGen og(obj, f2); | 1202 | QPDFObjGen og(obj, f2); |
| 1199 | if (!m->deleted_objects.count(obj)) { | 1203 | if (!m->deleted_objects.count(obj)) { |
| 1200 | // deleted_objects stores the uncompressed objects removed from the xref table at the start | 1204 | // deleted_objects stores the uncompressed objects removed from the xref table at the start |
qpdf/qpdf.testcov
| @@ -105,6 +105,7 @@ QPDF_encryption xref stream from encrypted file 0 | @@ -105,6 +105,7 @@ QPDF_encryption xref stream from encrypted file 0 | ||
| 105 | QPDFJob unable to filter 0 | 105 | QPDFJob unable to filter 0 |
| 106 | QUtil non-trivial UTF-16 0 | 106 | QUtil non-trivial UTF-16 0 |
| 107 | QPDF xref overwrite object 0 | 107 | QPDF xref overwrite object 0 |
| 108 | +QPDF xref overwrite invalid objgen 0 | ||
| 108 | QPDF decoding error warning 0 | 109 | QPDF decoding error warning 0 |
| 109 | qpdf-c called qpdf_init 0 | 110 | qpdf-c called qpdf_init 0 |
| 110 | qpdf-c called qpdf_cleanup 0 | 111 | qpdf-c called qpdf_cleanup 0 |
qpdf/qtest/qpdf/obj0-check.out
| @@ -5,5 +5,4 @@ checking obj0.pdf | @@ -5,5 +5,4 @@ checking obj0.pdf | ||
| 5 | PDF Version: 1.3 | 5 | PDF Version: 1.3 |
| 6 | File is not encrypted | 6 | File is not encrypted |
| 7 | File is not linearized | 7 | File is not linearized |
| 8 | -WARNING: obj0.pdf (offset 15): object with ID 0 | ||
| 9 | qpdf: operation succeeded with warnings | 8 | qpdf: operation succeeded with warnings |