Commit 328c4f97 for libheif
commit 328c4f97afe915c26ba5991362c5ed92e69f1a1b
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Sun Aug 23 23:52:39 2026 +0200
transfer_channel_from_image_as(): check that source channel exists
diff --git a/libheif/image/pixelimage.cc b/libheif/image/pixelimage.cc
index a43601c7..ce8ac691 100644
--- a/libheif/image/pixelimage.cc
+++ b/libheif/image/pixelimage.cc
@@ -1048,13 +1048,22 @@ Error HeifPixelImage::transfer_channel_from_image_as(const std::shared_ptr<HeifP
// Find and remove the component from source
ComponentStorage plane;
+ bool source_channel_found = false;
for (auto it = source->m_storage.begin(); it != source->m_storage.end(); ++it) {
if (it->m_channel == src_channel) {
plane = *it;
source->m_storage.erase(it);
+ source_channel_found = true;
break;
}
}
+
+ if (!source_channel_found) {
+ return {heif_error_Usage_error,
+ heif_suberror_Unspecified,
+ "Channel cannot be transferred because it was not found in the source image."};
+ }
+
source->m_memory_handle.free(plane.allocation_size);
// Move the matching ComponentDescription(s) from source to destination.