LibRaw HuffTable::initval heap-based buffer overflow vulnerability
The Huffman table initialisation routine in LibRaw's lossless JPEG decoder trusts the per-length code counts read from an image file without checking them, so the lookup table is allocated too small for the number of entries later written. A crafted RAW file can therefore overflow the heap buffer, which the report rates as potentially allowing code execution.
Originally disclosed on Cisco Talos
A heap-based buffer overflow vulnerability exists in the HuffTable::initval functionality of LibRaw Commit 0b56545 and Commit d20315b. A specially crafted malicious file can lead to a heap buffer overflow.
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 code assumes the per-length Huffman code counts from the file always describe a valid table, so it sizes the lookup table from the longest code length alone and never checks that the total number of entries written fits that allocation.
Impact
A malicious file could cause a heap buffer overflow, which the report scores as high impact for confidentiality, integrity and availability, though it does not demonstrate code execution.
What the attacker needed
Victim opens a crafted RAW file; software uses LibRaw to decode it
The fix
The counts in the bits array should be validated, or the table sized from the total number of entries actually written, before the fill loop runs.
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 photo files are compressed, and the decoder uses a lookup table to unpack them quickly. The size of that table is worked out from numbers stored in the file, and those numbers are never checked, so a file can claim more codes than the table has room for. Writing past the end of a reserved block of memory 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.