Skip to content
Memory corruption Advisory Advanced CVE-2026-21413

LibRaw lossless_jpeg_load_raw heap-based buffer overflow vulnerability

The lossless JPEG decoder in LibRaw computes a column index from attacker-controlled CR2Slice tag values without checking it against the allocated image width. A crafted RAW file can therefore write 16-bit values past the end of a heap buffer, corrupting memory and potentially allowing code execution.

Francesco Benvenuto Follow

Originally disclosed on Cisco Talos

Critical 9.8 View original

A heap-based buffer overflow vulnerability exists in the losslessjpegloadraw functionality of LibRaw Commit 0b56545 and Commit d20315b. A specially crafted malicious file can lead to a heap buffer overflow.

Francesco Benvenuto, 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

The column index derived from the CR2Slice tag is used to index the raw image buffer without being validated against the buffer width, while only the row index is checked.

Impact

The out-of-bounds write can corrupt the heap and potentially lead to code execution, with the written value fully controlled by the attacker.

What the attacker needed

Victim opens a crafted CR2 file; application calls unpack() on it

The fix

The column index should be validated against the allocated buffer width before being used, as the row index already is.

How it was found

  1. Open a crafted CR2 file with LibRaw so that unpack() is called.
  2. The decoder reads the CR2Slice tag values from the file.
  3. The lossless JPEG decoder computes the column index from those slice values.
  4. The computed column exceeds the allocated image width and the pixel value is written out of bounds.

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.

RAW image files contain extra metadata that tells the decoder how to arrange the picture data. LibRaw trusted one of those numbers when working out where to store each pixel, so a file with a large value made it write past the end of its memory buffer. Writing outside a buffer can crash the program or, in the worst case, let an attacker 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 Francesco Benvenuto

View all

152 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.