Use after free in Blink (CVE-2026-7974)
A range-based loop in Blink's image downloader iterates over a vector of fetchers while a callback synchronously erases elements from that same vector, leaving stale pointers in the trailing slots. The loop then dereferences a freed fetcher and calls Dispose() on it, a use-after-free that could potentially be exploited for code execution in the renderer.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 37 days
Project Fortify, an experimental security project, has identified the following potential security issue.
Overview: A range-based for loop in ImageDownloaderImpl::ContextDestroyed iterates over a vector of unique_ptrs. Calling Dispose() on the elements synchronously removes them from the vector, leaving stale pointers in the vector's trailing slots that the loop subsequently dereferences, leading to a Use-After-Free.
Affected files:
third_party/blink/renderer/modules/image_downloader/image_downloader_impl.ccthird_party/blink/renderer/modules/image_downloader/multi_resolution_image_resource_fetcher.cc
Estimated timestamp from git blame: 2020-02-16
Overview
There is a potential Use-After-Free (UAF) vulnerability in ImageDownloaderImpl::ContextDestroyed() in the renderer process. The issue stems from a range-based for loop iterating over WTF::Vector<std::unique_ptr<MultiResolutionImageResourceFetcher>> image_fetchers_. The loop body calls a method on the unique_ptr that synchronously mutates the vector by erasing the element. Because WTF::Vector::erase() uses memmove to shift elements but does not clear the trailing slots, the loop continues to iterate (using its cached end iterator) and eventually dereferences a stale unique_ptr in the uncleared memory, causing a UAF when it calls Dispose() on an already-deleted object.
Technical Details
- The Loop:
ImageDownloaderImpl::ContextDestroyed()iterates over theimage_fetchers_vector using a range-based for loop:C++ void ImageDownloaderImpl::ContextDestroyed() { for (const auto& fetcher : image_fetchers_) { fetcher->Dispose(); } image_fetchers_.clear(); } - Synchronous Mutation:
MultiResolutionImageResourceFetcher::Dispose()synchronously runs its callback:std::move(callback_).Run(...). - Vector Erasure: This callback is bound to
ImageDownloaderImpl::DidFetchImage(), which finds the corresponding fetcher inimage_fetchers_and erases it:it = image_fetchers_.erase(it);. - Stale Pointers:
WTF::Vector::erase()callsTypeOperations::MoveOverlapping()(usingmemmove) to shift the remaining elements left. Crucially, because the default allocator isPartitionAlloc(wherekIsGarbageCollectedis false),ClearUnusedSlots()is a no-op. The trailing slots of the vector's backing buffer retain the raw bit patterns of the movedunique_ptrs. - The UAF: The range-based for loop caches the
enditerator initially. Even though the vector shrinks with each erasure, the loop continues iterating until it reaches the originalend. It eventually encounters the uncleared, staleunique_ptrs in the trailing slots. These point to memory that was freed in previous iterations. The loop dereferences the stale pointer and callsDispose()on the attacker-controlled, freed memory chunk.
Potential Exploitability
This vulnerability could potentially lead to Remote Code Execution (RCE) in the renderer process.
Inside Dispose(), the code accesses the callback_ member, which is a base::OnceCallback. Executing this callback requires reading the bind_state_ pointer (a scoped_refptr<BindStateBase>) to find the polymorphic_invoke_ function pointer.
An attacker could attempt to groom the heap to reclaim the memory chunk of the freed MultiResolutionImageResourceFetcher during the synchronous window provided immediately after the erasure (e.g., during the Mojo IPC allocations in DidDownloadImage, which is called right after DidFetchImage). By controlling the contents of the reclaimed memory, the attacker could forge the BindStateHolder and hijack control flow.
This issue is not protected by MiraclePtr (BackupRefPtr) because the stale pointer is a raw T* stored inside a standard std::unique_ptr within the WTF::Vector's raw backing store, completely bypassing BRP checks.
Suggested Fix
To fix this, the image_fetchers_ vector should be cleared safely before iterating, for example by swapping it with a local vector or taking ownership using std::exchange:
void ImageDownloaderImpl::ContextDestroyed() {
auto fetchers = std::move(image_fetchers_);
for (const auto& fetcher : fetchers) {
fetcher->Dispose();
}
}
(Note: These are suggested steps based on code analysis; a working proof of concept has not yet been executed to confirm exact exploitation parameters.)
Evaluated with Chrome root at commit: 876d480da1f794d87813cfa2e6ff4fcf9771e939
Results so far have been promising, but there can be wrong deductions. If this proves to be a false positive, please close as WAI; data from false positives will be used to improve accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.
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 loop mutates the vector it is iterating over, and the vector's erase does not clear the trailing slots, so the cached end iterator lets the loop reach stale pointers.
Impact
This could potentially lead to remote code execution in the renderer process, though the author notes no working proof of concept has been executed to confirm exploitation.
What the attacker needed
Renderer process reachable; heap grooming to reclaim freed chunk
The fix
The vector should be moved into a local variable before iterating so the loop no longer walks a container that is being mutated.
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.
When a program frees an object but keeps a pointer to it and later uses that pointer, that is a use-after-free. Here a loop walks a list of image fetchers, and each step removes an item from the same list, so the loop ends up reading leftover slots that point to memory already freed. An attacker who can control what lands in that freed memory might redirect the program's execution.
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.