Double-free and attempting free on address which was not malloc()-ed on Firefox libwebp WebPEncodeRGBA
A double-free occurs in Firefox's libwebp encoder when memory allocation fails during a loop, causing the same pointer to be freed twice. An attacker could trigger this by visiting a crafted HTML page, leading to a crash.
Originally disclosed on Mozilla
- Fixed in 15 days
- Paid in 22 days
- Disclosed after 15 days
Created attachment 9320173 testcase.html
When visiting testcase.html on Firefox ASan 32-bit, the AddresSanitizer print output attempting double-free or attempting free on address which was not malloc()-ed: the stack trace show its occur on media/libwebp library.
From my analysis on ASan stack trace it occurs on libwebp alpha_enc.c ApplyFiltersAndEncode function loop, at first loop the ok=1 it execute VP8BitWriterOutput(&best.bw) to free best.bw pointer then the code assign best = trial pointer. It then execute else branch that execute VP8BitWriterWipeOut(&trial.bw) that freed the trial.bw pointer.
On the second loop ok variable return 0 because AllocateTransformBuffer function using malloc but return NULL due to OOM, that cause ok to return 0, inside that loop it execute else branch that execute VP8BitWriterWipeOut(&trial.bw) that freed the trial.bw pointer.
Then when loop is done and ok variable is still 0, it take else branch that execute VP8BitWriterWipeOut(&best.bw) which freed up the best.bw pointer, however the pointer is still assigned to trial.bw that already freed up on the second loop which lead to AddressSanitizer: attempting double-free
I've filed this security issue on https://bugs.chromium.org/p/webp Issue 603. They are currently working on the patch. I'll post update when they change the issue status to Fixed.
Steps to reproduce:
- Compile Firefox 32-bit with AddressSanitizer
- Visit attached testcase.html
- Firefox tab crashed with
AddressSanitizer: attempting double-freeorAddressSanitizer: attempting free on address which was not malloc()-ed
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
Likely a logic error in the encoder's loop: after a successful iteration, the 'best' pointer is set to 'trial', but on a later failed iteration the 'trial' pointer is freed again, and then 'best' (now pointing to the same freed memory) is freed once more.
Impact
Visiting a malicious page could crash the browser tab; the report does not claim code execution.
What the attacker needed
Victim visits a crafted HTML page; Firefox built with AddressSanitizer (32-bit)
How it was found
- Compile Firefox 32-bit with AddressSanitizer
- Visit the attached testcase.html
- Observe the tab crash with an AddressSanitizer double-free error
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.
A double-free is a memory bug where the same chunk of memory is freed twice. This can crash the program or, in some cases, let an attacker run their own code. Here, a specially crafted web page makes Firefox's image encoder free the same memory twice, crashing the browser tab.
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.