Commit edc12502 for libheif
commit edc1250260ffcbaa9cf16a4158a982382d5f1348
Author: Niebelungen <dong_xr2000@163.com>
Date: Fri Feb 27 23:06:19 2026 +0800
Validate stsc sample coverage against stsz/stts
diff --git a/libheif/sequences/track.cc b/libheif/sequences/track.cc
index e08923bb..b825a90f 100644
--- a/libheif/sequences/track.cc
+++ b/libheif/sequences/track.cc
@@ -407,6 +407,14 @@ Error Track::load(const std::shared_ptr<Box_trak>& trak_box)
previous_sample_description_index = sampleToChunk.sample_description_index;
}
+ if (current_sample_idx != m_stsz->num_samples()) {
+ return {
+ heif_error_Invalid_input,
+ heif_suberror_Unspecified,
+ "Number of samples covered by 'stsc' does not match 'stsz'/'stts'."
+ };
+ }
+
// --- read sample auxiliary information boxes
std::vector<std::shared_ptr<Box_saiz> > saiz_boxes = stbl->get_child_boxes<Box_saiz>();