Skip to content
Memory corruption Write-up Advanced

Finding Vulnerability Variants at Scale

A JPEG decompression routine in jpeg-recompress calculated an image buffer size by multiplying attacker-controlled width and height values, causing an integer overflow that allocated a too-small buffer. A subsequent heap buffer overflow could crash the program and potentially overwrite adjacent memory.

blackwinghq.com

Published on blackwinghq.com

Filed by Franco Belman (@0xFBFBFBFB) on October 15, 2024

The author, on blackwinghq.com

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 write-up has not been written yet. The Original tab links to the source.

How it worked

Impact

The integer overflow leads to a heap buffer overflow that can overwrite adjacent data and crash the program; the text does not claim remote code execution.

What the attacker needed

Ability to supply a crafted JPEG file; target uses libjpeg or a fork for decompression

The fix

The text does not state a specific fix for jpeg-recompress; it notes that libjpeg's documentation lacks guidance on safely creating the buffer, implying that proper bounds checking and overflow-safe size calculation should be used.

How it was found

  1. Compile jpeg-recompress with instrumentation using AFL-CC.
  2. Fuzz the instrumented binary with AFL++ using JPEG files from the go-fuzz-corpus as input.
  3. A crash occurred within one minute of fuzzing.
  4. Execute jpeg-recompress with the crashing JPEG as input and use GDB for debugging.
  5. GDB indicated that the cause of the crash was a segmentation fault.

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 write-up has not been written yet. The Original tab links to the source.

When a program reads an image, it uses the image's stated width and height to decide how much memory to reserve. If those numbers are huge, the multiplication can wrap around to a tiny number, so the program reserves too little memory and then writes the image data past the end of that space. This is called a heap buffer overflow and can crash the program or let an attacker corrupt memory.

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.

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.