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
This commit is contained in:
RHEL Packaging Agent 2026-08-07 08:19:31 +00:00
parent 5630cab5e5
commit aad4fe02a7
2 changed files with 79 additions and 1 deletions

View File

@ -0,0 +1,70 @@
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()
{

View File

@ -7,7 +7,7 @@
Summary: Library for reading RAW files obtained from digital photo cameras
Name: LibRaw
Version: 0.21.1
Release: 3%{?dist}
Release: 4%{?dist}
License: BSD and LGPLv2
URL: http://www.libraw.org
@ -31,6 +31,10 @@ Patch2: LibRaw-CVE-2026-21413-TALOS-2026-2331.patch
# https://redhat.atlassian.net/browse/RHEL-165375
Patch3: LibRaw-CVE-2026-24450-TALOS-2026-2363.patch
# https://redhat.atlassian.net/browse/RHEL-219218
# https://github.com/LibRaw/LibRaw/commit/233ae06de75b083407f65b437cb1da1bdbb52076
Patch4: LibRaw-CVE-2026-51235.patch
Provides: bundled(dcraw) = 9.25
%description
@ -125,6 +129,10 @@ rm -fv %{buildroot}%{_libdir}/lib*.la
%changelog
* Fri Aug 07 2026 RHEL Packaging Agent <redhat-ymir-agent@redhat.com> - 0.21.1-4
- Fix CVE-2026-51235: integer overflow in image size calculations
Resolves: RHEL-219218
* Tue Apr 28 2026 Debarshi Ray <rishi@fedoraproject.org> - 0.21.1-3
- Fix CVE-2026-21413 and CVE-2026-24450
Resolves: RHEL-165375, RHEL-165464