Skip to content
Memory corruption Write-up Advanced

How a double-free bug in WhatsApp turns to RCE

A double-free in the GIF decoding library bundled with WhatsApp for Android let a crafted GIF corrupt a GifInfo structure and overwrite a function pointer, so a malicious GIF could give code execution in WhatsApp's context when the victim opened the Gallery view. The author chained this with an information leak to defeat ASLR and reach a remote shell.

Awakened Follow

Published on awakened1712.github.io

In this blog post, I’m going to share about a double-free vulnerability that I discovered in WhatsApp for Android, and how I turned it into an RCE. I informed this to Facebook.

Awakened, on awakened1712.github.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

Likely the reallocation path treats a zero-sized reallocation as a plain free but leaves the stale pointer in place, so a later zero-sized reallocation frees the same buffer again.

Impact

An attacker could achieve code execution in WhatsApp's context, but only on Android 8.1 and 9.0, and reliable exploitation needs a separate information disclosure to learn library addresses.

What the attacker needed

Victim receives a crafted GIF; victim opens WhatsApp Gallery; Android 8.1 or 9.0; address leak for reliable RCE

The fix

It was fixed in WhatsApp 2.19.244 and in version 1.2.18 of the upstream android-gif-drawable library.

How it was found

  1. Send a crafted GIF to the victim as a Document attachment so it is not converted.
  2. Wait for the victim to open the WhatsApp Gallery to pick a media file.
  3. The Gallery preview parses the GIF twice, triggering the double-free and the overwrite.
  4. The overwritten function pointer is called at the end of decoding, giving control of the program counter.

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.

A GIF file is made of several frames, and the app keeps one memory buffer to hold the decoded picture. If a frame has zero width or height, the code frees that buffer but keeps the old pointer, so the same memory gets freed twice. Later the app hands out that same memory twice, and the attacker's picture data lands on top of an internal structure that holds a function address, so the program jumps where the attacker wants.

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 from Meta

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.