aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2023-10-15 00:03:34 +0200
committerJay Berkenbilt <ejb@ql.org>2023-10-15 00:04:13 +0200
commit71566a2761fa7ec0fca418540325deca368cfb79 (patch)
treec666c9214c6ca6868e0304bf6c1989b79ba19047
parent9fc02e2f91c856c8b8cd7369ceecd5a89deedb37 (diff)
downloadqpdf-71566a2761fa7ec0fca418540325deca368cfb79.tar.zst
Write offsets as unsigned in linearization hint tables (fixes #1023)
-rw-r--r--ChangeLog3
-rw-r--r--include/qpdf/QPDF.hh6
-rw-r--r--libqpdf/QPDF_linearization.cc8
3 files changed, 13 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 2674cc06..22068042 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2023-10-14 Jay Berkenbilt <ejb@ql.org>
+ * Tweak linearization code to better handle files between 2 GB and
+ 4 GB in size. Fixes #1023.
+
* Fix serious bug: qpdf could discard a the character after an
escaped octal string. For content, this would only happen with QDF
or when normalizing content, but it could have happened in a
diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh
index 0281f5d0..2ca6005c 100644
--- a/include/qpdf/QPDF.hh
+++ b/include/qpdf/QPDF.hh
@@ -1437,6 +1437,12 @@ class QPDF
{
return QIntC::to_int(i);
}
+ template <typename T>
+ static unsigned long long
+ toULL(T const& i)
+ {
+ return QIntC::to_ulonglong(i);
+ }
class Members
{
diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc
index fe25c6d9..469b9933 100644
--- a/libqpdf/QPDF_linearization.cc
+++ b/libqpdf/QPDF_linearization.cc
@@ -1670,11 +1670,11 @@ QPDF::writeHPageOffset(BitWriter& w)
HPageOffset& t = m->page_offset_hints;
w.writeBitsInt(t.min_nobjects, 32); // 1
- w.writeBitsInt(toI(t.first_page_offset), 32); // 2
+ w.writeBits(toULL(t.first_page_offset), 32); // 2
w.writeBitsInt(t.nbits_delta_nobjects, 16); // 3
w.writeBitsInt(t.min_page_length, 32); // 4
w.writeBitsInt(t.nbits_delta_page_length, 16); // 5
- w.writeBitsInt(t.min_content_offset, 32); // 6
+ w.writeBits(toULL(t.min_content_offset), 32); // 6
w.writeBitsInt(t.nbits_delta_content_offset, 16); // 7
w.writeBitsInt(t.min_content_length, 32); // 8
w.writeBitsInt(t.nbits_delta_content_length, 16); // 9
@@ -1717,7 +1717,7 @@ QPDF::writeHSharedObject(BitWriter& w)
HSharedObject& t = m->shared_object_hints;
w.writeBitsInt(t.first_shared_obj, 32); // 1
- w.writeBitsInt(toI(t.first_shared_offset), 32); // 2
+ w.writeBits(toULL(t.first_shared_offset), 32); // 2
w.writeBitsInt(t.nshared_first_page, 32); // 3
w.writeBitsInt(t.nshared_total, 32); // 4
w.writeBitsInt(t.nbits_nobjects, 16); // 5
@@ -1749,7 +1749,7 @@ void
QPDF::writeHGeneric(BitWriter& w, HGeneric& t)
{
w.writeBitsInt(t.first_object, 32); // 1
- w.writeBitsInt(toI(t.first_object_offset), 32); // 2
+ w.writeBits(toULL(t.first_object_offset), 32); // 2
w.writeBitsInt(t.nobjects, 32); // 3
w.writeBitsInt(t.group_length, 32); // 4
}