Skip to content
Memory corruption Advisory Advanced CVE-2021-21784

Accusoft ImageGear JPG format SOF marker processing out-of-bounds write vulnerability

A malformed JPG file with two SOF markers can cause an out-of-bounds write in the handle_color_channel_with_high_precision function because the buffer size is computed from the first marker but the loop uses the width from the second marker. An attacker could exploit this to corrupt memory and potentially execute arbitrary code.

Emmanuel Tacheau Follow

Originally disclosed on Cisco Talos

Critical 9.8 View original

An out-of-bounds write vulnerability exists in the JPG format SOF marker processing of Accusoft ImageGear 19.8. A specially crafted malformed file can lead to memory corruption.

Emmanuel Tacheau, on Cisco Talos

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the buffer size for raster_buffer is calculated using the first SOF marker's width and precision, but the loop that writes to it uses the width from a second SOF marker with an invalid precision, causing a mismatch and overflow.

Impact

This out-of-bounds write can lead to memory corruption and potentially arbitrary code execution.

What the attacker needed

Victim opens a malicious JPG file; no special privileges required

How it was found

  1. Create a JPG file containing two SOF markers: the first with valid precision (8, 12, or 16) and the second with an invalid precision value (e.g., 0xD).
  2. Load the malformed JPG file using the vulnerable ImageGear library.
  3. The first SOF marker is parsed and a valid HDIB object (and raster_buffer) is created based on its width, precision, and component count.
  4. The second SOF marker is parsed, but the HDIB object allocation fails due to the invalid precision, so raster_buffer is not updated.
  5. Because the second SOF marker has precision not equal to 8, the function handle_color_channel_with_high_precision is called via jpeg_raster_set, using the width from the first marker but with the assumption of higher precision.
  6. The do-while loop writes past the end of the allocated raster_buffer, causing an out-of-bounds write and memory corruption.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This report describes a bug in an image processing library. When the library reads a specially crafted JPG file, it writes data past the end of a memory buffer, which can crash the program or allow an attacker to run their own code.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by Emmanuel Tacheau

View all

58 more disclosed reports, best first.

More from Cisco Talos

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.