-
CVSS Score
-Basic Information
CVE ID
-
GHSA ID
-
EPSS Score
-
CWE
-
Published
-
Updated
-
KEV Status
-
Technology
-
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.
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. If ptr 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 on rindex, gindex, bindex and advances the pointer by ps (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 within get_word_rgb_row.start_input_ppm, which sets up the function pointers for pixel row reading (like source->pub.get_pixel_rows = get_word_rgb_row;), is also modified. It now includes checks to prevent assigning get_word_rgb_row if a color PPM is being loaded into an incompatible buffer type (like grayscale). For example, it adds if (IsExtRGB(cinfo->in_color_space)) before assigning get_word_rgb_row for 16-bit PPMs, and ERREXITs if not. These changes in start_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 in get_word_rgb_row, happens within get_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.KEV Misses 88% of Exploited CVEs- Get the report