Commit 9d1bfc9e for libheif
commit 9d1bfc9e829b3b53e6d8d8690655e8be7a5cedc4
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Thu Dec 25 21:07:10 2025 +0100
check image size against maximum range
diff --git a/libheif/api/libheif/heif_image_handle.cc b/libheif/api/libheif/heif_image_handle.cc
index 13a6b570..ada29271 100644
--- a/libheif/api/libheif/heif_image_handle.cc
+++ b/libheif/api/libheif/heif_image_handle.cc
@@ -44,7 +44,13 @@ heif_item_id heif_image_handle_get_item_id(const heif_image_handle* handle)
int heif_image_handle_get_width(const heif_image_handle* handle)
{
if (handle && handle->image) {
- return handle->image->get_width();
+ uint32_t w = handle->image->get_width();
+ if (w > INT_MAX) {
+ return 0;
+ }
+ else {
+ return static_cast<int>(w);
+ }
}
else {
return 0;
@@ -55,7 +61,13 @@ int heif_image_handle_get_width(const heif_image_handle* handle)
int heif_image_handle_get_height(const heif_image_handle* handle)
{
if (handle && handle->image) {
- return handle->image->get_height();
+ uint32_t h = handle->image->get_height();
+ if (h > INT_MAX) {
+ return 0;
+ }
+ else {
+ return static_cast<int>(h);
+ }
}
else {
return 0;
diff --git a/libheif/api/libheif/heif_image_handle.h b/libheif/api/libheif/heif_image_handle.h
index f02b850f..9e5a152f 100644
--- a/libheif/api/libheif/heif_image_handle.h
+++ b/libheif/api/libheif/heif_image_handle.h
@@ -53,10 +53,17 @@ int heif_image_handle_is_primary_image(const heif_image_handle* handle);
LIBHEIF_API
heif_item_id heif_image_handle_get_item_id(const heif_image_handle* handle);
-// Get the resolution of an image.
+/** Get the image width.
+ *
+ * If 'handle' is invalid (NULL) or if the image size exceeds the range of `int`, 0 is returned.
+ */
LIBHEIF_API
int heif_image_handle_get_width(const heif_image_handle* handle);
+/** Get the image height.
+ *
+ * If 'handle' is invalid (NULL) or if the image size exceeds the range of `int`, 0 is returned.
+ */
LIBHEIF_API
int heif_image_handle_get_height(const heif_image_handle* handle);