Miggo Logo

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

EPSS Score
0.18387%
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 AIMiggo AI

Miggo AIRoot 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.

  1. 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. 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.
  2. The function 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.

Vulnerable functions

Only Mi**o us*rs **n s** t*is s**tion

WAF Protection Rules

WAF Rule

T** PPM r****r in li*jp**-tur*o t*rou** *.*.** mis**n*l*s us* o* tjLo**Im*** *or lo**in* * **-*it *in*ry PPM *il* into * *r*ys**l* *u***r *n* lo**in* * **-*it *in*ry P*M *il* into *n R** *u***r. T*is is r*l*t** to * ***p-**s** *u***r ov*r*low in t**

Reasoning

T** vuln*r**ility **s*ription (*V*-****-*****) *xpli*itly st*t*s t**t t** ***p-**s** *u***r ov*r*low o**urs in t** `**t_wor*_r**_row` *un*tion in `r*ppm.*`. T*is **pp*ns w**n `tjLo**Im***` is us** to lo** * **-*it *in*ry PPM *il* (*olor) into * *r*ys