Commit d035da94 for libheif
commit d035da94ba7835b597550337f4aedb51f3b0ce82
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Thu Jul 2 12:38:36 2026 +0200
Add size-0 'mini' and 'moov' regression tests and fixtures (#1857)
Add PoC fixtures and file-layout regression tests exercising the size-0
box handling for the 'mini' and 'moov' boxes:
- tests/data/mini_size_zero.avif: a MIAF low-overhead 'mini' AVIF
(256x256) with the 'mini' box size field set to 0.
- tests/data/moov_size_zero.heif: a sequence laid out as ftyp + mdat +
moov (the common non-fast-start ordering) with the trailing 'moov'
box size field set to 0.
Both fixtures are rejected by the pre-fix parser ("Cannot read <box>
with unspecified size") and read correctly afterwards.
diff --git a/tests/data/mini_size_zero.avif b/tests/data/mini_size_zero.avif
new file mode 100644
index 00000000..fe5b358f
Binary files /dev/null and b/tests/data/mini_size_zero.avif differ
diff --git a/tests/data/moov_size_zero.heif b/tests/data/moov_size_zero.heif
new file mode 100644
index 00000000..0e658104
Binary files /dev/null and b/tests/data/moov_size_zero.heif differ
diff --git a/tests/file_layout.cc b/tests/file_layout.cc
index afcf6140..fa2f303a 100644
--- a/tests/file_layout.cc
+++ b/tests/file_layout.cc
@@ -25,6 +25,7 @@
*/
#include "catch_amalgamated.hpp"
#include "libheif/heif.h"
+#include "libheif/heif_sequences.h"
#include "api_structs.h"
#include <cstdint>
#include <stdio.h>
@@ -71,3 +72,45 @@ TEST_CASE("meta box with size 0 (extends to end of file)") {
heif_image_handle_release(handle);
heif_context_free(context);
}
+
+
+TEST_CASE("mini box with size 0 (extends to end of file)") {
+ // A top-level 'mini' box (MIAF low-overhead AVIF) with a box size of 0, which
+ // per ISO/IEC 14496-12 clause 4.2 means it extends to the end of the file.
+ auto istr = std::unique_ptr<std::istream>(new std::ifstream(tests_data_directory + "/mini_size_zero.avif", std::ios::binary));
+ auto reader = std::make_shared<StreamReader_istream>(std::move(istr));
+
+ FileLayout file;
+ Error err = file.read(reader, heif_get_global_security_limits());
+
+ REQUIRE(err.error_code == heif_error_Ok);
+ REQUIRE(file.get_mini_box() != nullptr);
+
+ heif_context* context = get_context_for_test_file("mini_size_zero.avif");
+ heif_image_handle* handle = get_primary_image_handle(context);
+ REQUIRE(heif_image_handle_get_ispe_width(handle) == 256);
+ REQUIRE(heif_image_handle_get_ispe_height(handle) == 256);
+ heif_image_handle_release(handle);
+ heif_context_free(context);
+}
+
+
+TEST_CASE("moov box with size 0 (extends to end of file)") {
+ // A sequence file laid out as 'ftyp' + 'mdat' + 'moov', where the trailing
+ // 'moov' box uses a box size of 0 (extends to end of file, per ISO/IEC
+ // 14496-12 clause 4.2). This is the common non-fast-start ordering.
+ auto istr = std::unique_ptr<std::istream>(new std::ifstream(tests_data_directory + "/moov_size_zero.heif", std::ios::binary));
+ auto reader = std::make_shared<StreamReader_istream>(std::move(istr));
+
+ FileLayout file;
+ Error err = file.read(reader, heif_get_global_security_limits());
+
+ REQUIRE(err.error_code == heif_error_Ok);
+ REQUIRE(file.get_moov_box() != nullptr);
+
+ // The resolved 'moov' box must yield a readable sequence track.
+ heif_context* context = get_context_for_test_file("moov_size_zero.heif");
+ REQUIRE(heif_context_has_sequence(context) == 1);
+ REQUIRE(heif_context_number_of_sequence_tracks(context) == 1);
+ heif_context_free(context);
+}