Lhasa lha decode_level3_header Heap Corruption Vulnerability
A crafted LHA archive can set the level 3 header length field to a value smaller than the fixed header size, causing an integer underflow in the size calculation. The resulting huge read length is passed to a heap reallocation and read, letting an attacker overwrite heap memory with file-controlled content.
Originally disclosed on Cisco Talos
An exploitable integer underflow exists during calculation size for all headers in decodelevel3header function of Lhasa (lha) application. Smaller value of headerlen than LEVEL3HEADERLEN ( 32 ) cause during subtraction integer underflow and lead later to memory corruption via heap based 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 header length field is only checked against an upper bound, so a value below the fixed header size underflows the subtraction used as the read length.
Impact
An attacker who supplies a crafted archive could overwrite heap memory with controlled content, leading to a crash and potentially code execution.
What the attacker needed
Victim opens a crafted LHA archive
How it was found
- Open a crafted LHA archive whose level 3 header length field is smaller than the fixed header size.
- The program subtracts the already-read length from this value, producing a near-maximum size.
- The header buffer is reallocated to a smaller size, leaving the read pointer on freed memory.
- The program reads the huge length from the file into that pointer, overwriting heap memory.
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.
LHA is an old archive format, like a zip file. The program reads a number from the file saying how long the header is, then subtracts the size it already read. If the number is smaller than expected, the subtraction wraps around to a huge value, and the program then copies far more data than the buffer can hold, corrupting 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.