Commit 623a7750 for libheif
commit 623a775059363553abc5d228114da1ae368c47c8
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Thu Dec 18 14:51:05 2025 +0100
[BSD3] fix potential endless loop when trying to decode incomplete input data (#1640) second try
diff --git a/libheif/codecs/decoder.cc b/libheif/codecs/decoder.cc
index 48105a9d..4e6f6f54 100644
--- a/libheif/codecs/decoder.cc
+++ b/libheif/codecs/decoder.cc
@@ -344,6 +344,18 @@ Error Decoder::decode_sequence_frame_from_compressed_data(bool upload_configurat
return dataResult.error();
}
+ // Check that we are pushing at least some data into the decoder.
+ // Some decoders (e.g. aom) do not complain when the input data is empty and we might
+ // get stuck in an endless decoding loop, waiting for the decompressed image.
+
+ if (dataResult->size() == 0) {
+ return Error{
+ heif_error_Invalid_input,
+ heif_suberror_Unspecified,
+ "Input with empty data extent."
+ };
+ }
+
//std::cout << "Decoder::decode_sequence_frame_from_compressed_data push " << dataResult->size() << "\n";
if (m_decoder_plugin->plugin_api_version >= 5 && m_decoder_plugin->push_data2) {
err = m_decoder_plugin->push_data2(m_decoder, dataResult->data(), dataResult->size(), user_data);
diff --git a/libheif/image-items/image_item.cc b/libheif/image-items/image_item.cc
index 797df4ec..ce21e092 100644
--- a/libheif/image-items/image_item.cc
+++ b/libheif/image-items/image_item.cc
@@ -937,18 +937,6 @@ Result<std::shared_ptr<HeifPixelImage>> ImageItem::decode_compressed_image(const
decoder->set_data_extent(std::move(extent));
- // Check that we are pushing at least some data into the decoder.
- // Some decoders (e.g. aom) do not complain when the input data is empty and we might
- // get stuck in an endless decoding loop, waiting for the decompressed image.
-
- if (extent.m_size == 0) {
- return Error{
- heif_error_Invalid_input,
- heif_suberror_Unspecified,
- "Input with empty data extent."
- };
- }
-
return decoder->decode_single_frame_from_compressed_data(options,
get_context()->get_security_limits());
}