Commit 6870c581 for libheif
commit 6870c58109f4b5fab52380640a6a34207a1910ce
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Mon Oct 26 09:34:36 2026 +0100
libde265: reject NAL units larger than INT_MAX
de265_push_NAL() takes the NAL length as 'int', so a 4-byte length
prefix of 2^31 or more turned negative. libde265 1.1.0 to 1.1.2 do not
reject negative lengths before copying the data; 1.1.3 does. Refuse such
NAL units in the plugin so that all libde265 versions are covered.
diff --git a/libheif/plugins/decoder_libde265.cc b/libheif/plugins/decoder_libde265.cc
index 2f86ebe5..c1953c39 100644
--- a/libheif/plugins/decoder_libde265.cc
+++ b/libheif/plugins/decoder_libde265.cc
@@ -357,6 +357,16 @@ static heif_error libde265_v1_push_data2(void* decoder_raw, const void* data, si
};
}
+ // de265_push_NAL() takes the length as 'int'. Larger sizes would turn negative,
+ // which libde265 < 1.1.3 does not reject before copying the data.
+ if (nal_size > static_cast<uint32_t>(std::numeric_limits<int>::max())) {
+ return {
+ heif_error_Decoder_plugin_error,
+ heif_suberror_Unspecified,
+ "NAL unit size exceeds 2 GB"
+ };
+ }
+
#if 0
FILE* fh = fopen("data.h265", "a");
fputc(0, fh);