CVE-2021-46822:
The PPM reader in libjpeg-turbo through 2.0.90 mishandles use of tjLoadImage for loading a 16-bit...
5.5
CVSS Score
3.1
Basic Information
CVE ID
GHSA ID
EPSS Score
0.18387%
CWE
Published
6/19/2022
Updated
1/27/2023
KEV Status
No
Technology
-
Technical Details
CVSS Vector
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H
Vulnerability Intelligence
Miggo AI
Root Cause Analysis
The vulnerability description (CVE-2021-46822) explicitly states that the heap-based buffer overflow occurs in the get_word_rgb_row
function in rdppm.c
. This happens when tjLoadImage
is used to load a 16-bit binary PPM file (color) into a grayscale buffer.
The provided commit f35fd27ec641c42d6b115bfa595e483ec58188d2
modifies rdppm.c
.
- The function
get_word_rgb_row
itself is changed. The critical modification is how it writes pixel data. The previous code used*ptr++
three times to write R, G, and B components. Ifptr
pointed to a buffer allocated for grayscale (i.e., smaller than needed for 3 components), this would cause a buffer overflow. The patch changes this to use indexed writes based onrindex
,gindex
,bindex
and advances the pointer byps
(pixel_size of the output buffer), making the write operation aware of the actual output buffer's structure. This change directly addresses the overflow mechanism withinget_word_rgb_row
. - The function
start_input_ppm
, which sets up the function pointers for pixel row reading (likesource->pub.get_pixel_rows = get_word_rgb_row;
), is also modified. It now includes checks to prevent assigningget_word_rgb_row
if a color PPM is being loaded into an incompatible buffer type (like grayscale). For example, it addsif (IsExtRGB(cinfo->in_color_space))
before assigningget_word_rgb_row
for 16-bit PPMs, andERREXIT
s if not. These changes instart_input_ppm
are mitigations to prevent the vulnerable condition from being reached. However, the actual overflow, as per the CVE and the nature of the fix inget_word_rgb_row
, happens withinget_word_rgb_row
when it's called with mismatched input (color PPM) and output buffer (grayscale). Therefore,get_word_rgb_row
is identified as the vulnerable function.