Commit 41ed4e31 for libheif
commit 41ed4e310a7364efda9dbd7a37fbb53951921113
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Tue Apr 14 17:10:28 2026 +0200
extend length/offset fields of iloc to 8 bytes when required
diff --git a/libheif/box.cc b/libheif/box.cc
index 510ca72f..81ed5c71 100644
--- a/libheif/box.cc
+++ b/libheif/box.cc
@@ -2142,9 +2142,24 @@ void Box_iloc::derive_box_version()
m_offset_size = 4;
m_length_size = 4;
- //m_base_offset_size = 4; // set above
m_index_size = 0;
+ // extent.length is already known; extent.offset within an item equals
+ // the cumulative length of all preceding extents (they are written sequentially).
+ // base_offset absorbs the absolute file position, so extent.offset is relative.
+ for (const auto& item : m_items) {
+ uint64_t cumulative_offset = 0;
+ for (const auto& extent : item.extents) {
+ if (cumulative_offset > 0xFFFFFFFF) {
+ m_offset_size = 8;
+ }
+ if (extent.length > 0xFFFFFFFF) {
+ m_length_size = 8;
+ }
+ cumulative_offset += extent.length;
+ }
+ }
+
set_version((uint8_t) min_version);
}