LibRaw/LibRaw-CVE-2026-51235.patch
RHEL Packaging Agent aad4fe02a7 Fix CVE-2026-51235: integer overflow in image size calculations
Backport upstream commit 233ae06 to fix CVE-2026-51235 in
LibRaw 0.21.1. The patch prevents integer overflows in image
size calculations and adds stricter dimension limits for
fuji-rotated images:

- Adds 8192-pixel width/height limits for fuji-rotated images
  in identify.cpp.
- Wraps allocation size factors in INT64() casts in
  raw2image.cpp to prevent 32-bit overflow.
- Uses UINT64() casts for malloc size in
  phaseone_processing.cpp to prevent overflow.

CVE: CVE-2026-51235
Upstream patches:
 - 233ae06de7.patch
Resolves: RHEL-219218

This commit was backported by Ymir, a Red Hat Enterprise Linux software maintenance AI agent.

Assisted-by: Ymir
2026-08-07 08:19:31 +00:00

71 lines
2.7 KiB
Diff

From e22301bd708b1d30a68115382d0541bcdf8aed50 Mon Sep 17 00:00:00 2001
From: Alex Tutubalin <lexa@lexa.ru>
Date: Wed, 13 May 2026 12:13:22 +0300
Subject: [PATCH] rotated fuji: stricter image size limits; raw2image(ex):
avoid possible 32-bit overflow on alloc size calculations
---
src/metadata/identify.cpp | 4 ++++
src/preprocessing/raw2image.cpp | 9 ++++-----
src/utils/phaseone_processing.cpp | 2 +-
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/metadata/identify.cpp b/src/metadata/identify.cpp
index aabbf85..8dd3b22 100644
--- a/src/metadata/identify.cpp
+++ b/src/metadata/identify.cpp
@@ -1215,6 +1215,10 @@ dng_skip:
// Prevent incorrect-sized fuji-rotated files
if (INT64(width)*INT64(height) > INT64(raw_width) * INT64(raw_height) * 8LL)
is_raw = 0;
+
+ // All 'fuji-rotated' images are 6Mpix or less, so 8k x 8k limit is OK
+ if(width > 8192 || height > 8192 || raw_width > 8192 || raw_height > 8192)
+ is_raw = 0;
}
else
{
diff --git a/src/preprocessing/raw2image.cpp b/src/preprocessing/raw2image.cpp
index 702cf29..bbcdb30 100644
--- a/src/preprocessing/raw2image.cpp
+++ b/src/preprocessing/raw2image.cpp
@@ -79,13 +79,12 @@ int LibRaw::raw2image(void)
if (imgdata.image)
{
imgdata.image = (ushort(*)[4])realloc(
- imgdata.image, S.iheight * S.iwidth * sizeof(*imgdata.image));
- memset(imgdata.image, 0, S.iheight * S.iwidth * sizeof(*imgdata.image));
+ imgdata.image, INT64(S.iheight) * INT64(S.iwidth) * sizeof(*imgdata.image));
+ memset(imgdata.image, 0, INT64(S.iheight) * INT64(S.iwidth) * sizeof(*imgdata.image));
}
else
imgdata.image =
- (ushort(*)[4])calloc(S.iheight * S.iwidth, sizeof(*imgdata.image));
-
+ (ushort(*)[4])calloc(INT64(S.iheight) * INT64(S.iwidth), sizeof(*imgdata.image));
libraw_decoder_info_t decoder_info;
get_decoder_info(&decoder_info);
@@ -392,7 +391,7 @@ int LibRaw::raw2image_ex(int do_subtract_black)
alloc_height = (t_alloc_height + IO.shrink) >> IO.shrink;
alloc_width = (t_alloc_width + IO.shrink) >> IO.shrink;
}
- int alloc_sz = alloc_width * alloc_height;
+ INT64 alloc_sz = INT64(alloc_width) * INT64(alloc_height);
if (imgdata.image)
{
diff --git a/src/utils/phaseone_processing.cpp b/src/utils/phaseone_processing.cpp
index b82988b..bef831d 100644
--- a/src/utils/phaseone_processing.cpp
+++ b/src/utils/phaseone_processing.cpp
@@ -21,7 +21,7 @@
void LibRaw::phase_one_allocate_tempbuffer()
{
// Allocate temp raw_image buffer
- imgdata.rawdata.raw_image = (ushort *)malloc(S.raw_pitch * S.raw_height);
+ imgdata.rawdata.raw_image = (ushort *)malloc(UINT64(S.raw_pitch) * UINT64(S.raw_height));
}
void LibRaw::phase_one_free_tempbuffer()
{