Commit 71566a2761fa7ec0fca418540325deca368cfb79
1 parent
9fc02e2f
Write offsets as unsigned in linearization hint tables (fixes #1023)
Showing
3 changed files
with
13 additions
and
4 deletions
ChangeLog
| 1 | 2023-10-14 Jay Berkenbilt <ejb@ql.org> | 1 | 2023-10-14 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * Tweak linearization code to better handle files between 2 GB and | ||
| 4 | + 4 GB in size. Fixes #1023. | ||
| 5 | + | ||
| 3 | * Fix serious bug: qpdf could discard a the character after an | 6 | * Fix serious bug: qpdf could discard a the character after an |
| 4 | escaped octal string. For content, this would only happen with QDF | 7 | escaped octal string. For content, this would only happen with QDF |
| 5 | or when normalizing content, but it could have happened in a | 8 | or when normalizing content, but it could have happened in a |
include/qpdf/QPDF.hh
| @@ -1437,6 +1437,12 @@ class QPDF | @@ -1437,6 +1437,12 @@ class QPDF | ||
| 1437 | { | 1437 | { |
| 1438 | return QIntC::to_int(i); | 1438 | return QIntC::to_int(i); |
| 1439 | } | 1439 | } |
| 1440 | + template <typename T> | ||
| 1441 | + static unsigned long long | ||
| 1442 | + toULL(T const& i) | ||
| 1443 | + { | ||
| 1444 | + return QIntC::to_ulonglong(i); | ||
| 1445 | + } | ||
| 1440 | 1446 | ||
| 1441 | class Members | 1447 | class Members |
| 1442 | { | 1448 | { |
libqpdf/QPDF_linearization.cc
| @@ -1670,11 +1670,11 @@ QPDF::writeHPageOffset(BitWriter& w) | @@ -1670,11 +1670,11 @@ QPDF::writeHPageOffset(BitWriter& w) | ||
| 1670 | HPageOffset& t = m->page_offset_hints; | 1670 | HPageOffset& t = m->page_offset_hints; |
| 1671 | 1671 | ||
| 1672 | w.writeBitsInt(t.min_nobjects, 32); // 1 | 1672 | w.writeBitsInt(t.min_nobjects, 32); // 1 |
| 1673 | - w.writeBitsInt(toI(t.first_page_offset), 32); // 2 | 1673 | + w.writeBits(toULL(t.first_page_offset), 32); // 2 |
| 1674 | w.writeBitsInt(t.nbits_delta_nobjects, 16); // 3 | 1674 | w.writeBitsInt(t.nbits_delta_nobjects, 16); // 3 |
| 1675 | w.writeBitsInt(t.min_page_length, 32); // 4 | 1675 | w.writeBitsInt(t.min_page_length, 32); // 4 |
| 1676 | w.writeBitsInt(t.nbits_delta_page_length, 16); // 5 | 1676 | w.writeBitsInt(t.nbits_delta_page_length, 16); // 5 |
| 1677 | - w.writeBitsInt(t.min_content_offset, 32); // 6 | 1677 | + w.writeBits(toULL(t.min_content_offset), 32); // 6 |
| 1678 | w.writeBitsInt(t.nbits_delta_content_offset, 16); // 7 | 1678 | w.writeBitsInt(t.nbits_delta_content_offset, 16); // 7 |
| 1679 | w.writeBitsInt(t.min_content_length, 32); // 8 | 1679 | w.writeBitsInt(t.min_content_length, 32); // 8 |
| 1680 | w.writeBitsInt(t.nbits_delta_content_length, 16); // 9 | 1680 | w.writeBitsInt(t.nbits_delta_content_length, 16); // 9 |
| @@ -1717,7 +1717,7 @@ QPDF::writeHSharedObject(BitWriter& w) | @@ -1717,7 +1717,7 @@ QPDF::writeHSharedObject(BitWriter& w) | ||
| 1717 | HSharedObject& t = m->shared_object_hints; | 1717 | HSharedObject& t = m->shared_object_hints; |
| 1718 | 1718 | ||
| 1719 | w.writeBitsInt(t.first_shared_obj, 32); // 1 | 1719 | w.writeBitsInt(t.first_shared_obj, 32); // 1 |
| 1720 | - w.writeBitsInt(toI(t.first_shared_offset), 32); // 2 | 1720 | + w.writeBits(toULL(t.first_shared_offset), 32); // 2 |
| 1721 | w.writeBitsInt(t.nshared_first_page, 32); // 3 | 1721 | w.writeBitsInt(t.nshared_first_page, 32); // 3 |
| 1722 | w.writeBitsInt(t.nshared_total, 32); // 4 | 1722 | w.writeBitsInt(t.nshared_total, 32); // 4 |
| 1723 | w.writeBitsInt(t.nbits_nobjects, 16); // 5 | 1723 | w.writeBitsInt(t.nbits_nobjects, 16); // 5 |
| @@ -1749,7 +1749,7 @@ void | @@ -1749,7 +1749,7 @@ void | ||
| 1749 | QPDF::writeHGeneric(BitWriter& w, HGeneric& t) | 1749 | QPDF::writeHGeneric(BitWriter& w, HGeneric& t) |
| 1750 | { | 1750 | { |
| 1751 | w.writeBitsInt(t.first_object, 32); // 1 | 1751 | w.writeBitsInt(t.first_object, 32); // 1 |
| 1752 | - w.writeBitsInt(toI(t.first_object_offset), 32); // 2 | 1752 | + w.writeBits(toULL(t.first_object_offset), 32); // 2 |
| 1753 | w.writeBitsInt(t.nobjects, 32); // 3 | 1753 | w.writeBitsInt(t.nobjects, 32); // 3 |
| 1754 | w.writeBitsInt(t.group_length, 32); // 4 | 1754 | w.writeBitsInt(t.group_length, 32); // 4 |
| 1755 | } | 1755 | } |