Commit e3b77e43d698073620d465944b0bde05d32259ce

Authored by m-holger
1 parent c6a393a5

Fix offsets in QPDF::resolveObjectsInStream warnings

As discussed in #1396.
libqpdf/QPDF_objects.cc
... ... @@ -1608,7 +1608,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
1608 1608 m->file->getName() + " object stream " + std::to_string(obj_stream_number),
1609 1609 +"object " + std::to_string(id) + " 0",
1610 1610 offset,
1611   - msg};
  1611 + msg,
  1612 + true};
1612 1613 };
1613 1614  
1614 1615 if (m->resolved_object_streams.count(obj_stream_number)) {
... ... @@ -1667,6 +1668,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
1667 1668 bool is_first = true;
1668 1669 for (unsigned int i = 0; i < n; ++i) {
1669 1670 auto tnum = readToken(input);
  1671 + auto id_offset = input.getLastOffset();
1670 1672 auto toffset = readToken(input);
1671 1673 if (!(tnum.isInteger() && toffset.isInteger())) {
1672 1674 throw damaged(0, input.getLastOffset(), "expected integer in object stream header");
... ... @@ -1677,13 +1679,13 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
1677 1679  
1678 1680 if (num == obj_stream_number) {
1679 1681 QTC::TC("qpdf", "QPDF ignore self-referential object stream");
1680   - warn(damaged(num, input.getLastOffset(), "object stream claims to contain itself"));
  1682 + warn(damaged(num, id_offset, "object stream claims to contain itself"));
1681 1683 continue;
1682 1684 }
1683 1685  
1684 1686 if (num < 1) {
1685 1687 QTC::TC("qpdf", "QPDF object stream contains id < 1");
1686   - warn(damaged(num, input.getLastOffset(), "object id is invalid"s));
  1688 + warn(damaged(num, id_offset, "object id is invalid"s));
1687 1689 continue;
1688 1690 }
1689 1691  
... ... @@ -1691,8 +1693,9 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
1691 1693 QTC::TC("qpdf", "QPDF object stream offsets not increasing");
1692 1694 warn(damaged(
1693 1695 num,
1694   - offset,
1695   - "offset is invalid (must be larger than previous offset " +
  1696 + input.getLastOffset(),
  1697 + "offset " + std::to_string(offset) +
  1698 + " is invalid (must be larger than previous offset " +
1696 1699 std::to_string(last_offset) + ")"));
1697 1700 continue;
1698 1701 }
... ... @@ -1702,7 +1705,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
1702 1705 }
1703 1706  
1704 1707 if (first + offset >= end_offset) {
1705   - warn(damaged(num, offset, "offset is too large"));
  1708 + warn(damaged(
  1709 + num, input.getLastOffset(), "offset " + std::to_string(offset) + " is too large"));
1706 1710 continue;
1707 1711 }
1708 1712  
... ...
qpdf/qtest/qpdf/issue-143.out
... ... @@ -14,9 +14,9 @@ WARNING: issue-143.pdf (object 1 0, offset 24): expected dictionary key but foun
14 14 WARNING: issue-143.pdf (object 1 0, offset 21): stream dictionary lacks /Length key
15 15 WARNING: issue-143.pdf (object 1 0, offset 84): attempting to recover stream length
16 16 WARNING: issue-143.pdf (object 1 0, offset 84): recovered stream length: 606
17   -WARNING: issue-143.pdf object stream 1 (object 0 0, offset 4): object id is invalid
18   -WARNING: issue-143.pdf object stream 1 (object 0 0, offset 15): object id is invalid
19   -WARNING: issue-143.pdf object stream 1 (object 6 0): offset is invalid (must be larger than previous offset 0)
20   -WARNING: issue-143.pdf object stream 1 (object 0 0, offset 27): object id is invalid
  17 +WARNING: issue-143.pdf object stream 1 (object 0 0, offset 0): object id is invalid
  18 +WARNING: issue-143.pdf object stream 1 (object 0 0, offset 11): object id is invalid
  19 +WARNING: issue-143.pdf object stream 1 (object 6 0, offset 21): offset 0 is invalid (must be larger than previous offset 0)
  20 +WARNING: issue-143.pdf object stream 1 (object 0 0, offset 23): object id is invalid
21 21 WARNING: issue-143.pdf object stream 1 (object 2 0, offset 33): expected dictionary key but found non-name object; inserting key /QPDFFake1
22 22 qpdf: issue-143.pdf: unable to find page tree
... ...
qpdf/qtest/qpdf/object-stream-self-ref.out
1   -WARNING: object-stream-self-ref.pdf object stream 1 (object 1 0, offset 2): object stream claims to contain itself
  1 +WARNING: object-stream-self-ref.pdf object stream 1 (object 1 0, offset 0): object stream claims to contain itself
2 2 qpdf: operation succeeded with warnings; resulting file may have some problems
... ...