Skip to content
Memory corruption Write-up Advanced

7-Zip: From Uninitialized Memory to Remote Code Execution

7-Zip's RAR decoder classes relied on the caller to initialise their state before first use, but a crafted RAR archive with a solid item using a different encoding method could cause the decoder to operate on uninitialised memory, leading to heap corruption. An attacker could exploit this to achieve remote code execution when a victim extracts the archive.

landave.io

Published on landave.io

After my previous post on the 7-Zip bugs CVE-2017-17969 and CVE-2018-5996, I continued to spend time on analyzing antivirus software. As it happens, I found a new bug that (as the last two bugs) turned out to affect 7-Zip as well.

The author, on landave.io

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

Root cause

The decoder classes did not initialise their full state in their constructors and instead relied on the caller to configure them with isSolid==false before the first item, which could be violated by a crafted archive.

Impact

An attacker could craft a RAR archive that, when extracted, leads to remote code execution; the exploit worked reliably on fully updated Windows systems, though ASLR was later enabled to mitigate it.

What the attacker needed

Victim extracts a crafted RAR archive; 7-Zip version before 18.05; Windows OS (for the exploit)

How it was found

  1. Create a RAR archive where the first item uses encoding method v1.
  2. Make the second item use encoding method v2 (or v3) and set its solid bit.
  3. Extract the archive using 7-Zip (e.g., via the context menu 'Extract Here').
  4. The first item sets solidStart to false, so the second item's decoder is not initialised and uses uninitialised memory.
  5. The uninitialised state can be controlled to cause heap corruption and achieve code execution.

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 unpacks a compressed file, it uses a decoder to turn the compressed data back into normal files. This decoder needs to be set up correctly before it starts. In this case, a specially crafted archive could trick the program into using a decoder that was never properly set up, so it used leftover memory from other parts of the program. That leftover memory could be controlled by the attacker to corrupt the program and 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.

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.