Commit eba287ff for libheif

commit eba287ffe46c6ffe208835915a6970b09e1cd984
Author: Dirk Farin <dirk.farin@gmail.com>
Date:   Thu Dec 25 21:25:42 2025 +0100

    consistency check of saiz/saio boxes

diff --git a/libheif/sequences/track.cc b/libheif/sequences/track.cc
index 42257c6b..d5a95ea3 100644
--- a/libheif/sequences/track.cc
+++ b/libheif/sequences/track.cc
@@ -385,6 +385,14 @@ Error Track::load(const std::shared_ptr<Box_trak>& trak_box)
   std::vector<std::shared_ptr<Box_saiz> > saiz_boxes = stbl->get_child_boxes<Box_saiz>();
   std::vector<std::shared_ptr<Box_saio> > saio_boxes = stbl->get_child_boxes<Box_saio>();

+  if (saio_boxes.size() != saiz_boxes.size()) {
+    return Error{
+      heif_error_Invalid_input,
+      heif_suberror_Unspecified,
+      "Boxes 'saiz' and `saio` must come in pairs."
+    };
+  }
+
   for (const auto& saiz : saiz_boxes) {
     uint32_t aux_info_type = saiz->get_aux_info_type();
     uint32_t aux_info_type_parameter = saiz->get_aux_info_type_parameter();
@@ -401,6 +409,14 @@ Error Track::load(const std::shared_ptr<Box_trak>& trak_box)
     }

     if (saio) {
+      if (saio->get_num_samples() != saiz->get_num_samples()) {
+        return Error{
+          heif_error_Invalid_input,
+          heif_suberror_Unspecified,
+          "Number of samples in 'saiz' box does not match 'saio' box."
+        };
+      }
+
       if (aux_info_type == fourcc("suid")) {
         m_aux_reader_content_ids = std::make_unique<SampleAuxInfoReader>(saiz, saio);
       }
@@ -409,6 +425,13 @@ Error Track::load(const std::shared_ptr<Box_trak>& trak_box)
         m_aux_reader_tai_timestamps = std::make_unique<SampleAuxInfoReader>(saiz, saio);
       }
     }
+    else {
+      return Error{
+        heif_error_Invalid_input,
+        heif_suberror_Unspecified,
+        "'saiz' box without matching 'saio' box."
+      };
+    }
   }

   // --- read track properties