Use after free in Codecs (CVE-2026-7348)
A use-after-free flaw in Blink's ImageDecodingStore occurs when a raw pointer is added to an intrusive list before a hash map insertion; if the insertion fails due to a duplicate key, the object is freed but the pointer remains. An attacker could trigger this via a progressive JPEG with large dimensions, potentially leading to remote code execution in the renderer process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 23 days
Project Fortify, an experimental security project, has identified the following potential security issue. If you're a feature owner CC-ed on this bug, please do your best to review these reports without the security team.
Overview: A Use-After-Free (UAF) vulnerability exists in ImageDecodingStore due to a raw pointer being appended to an intrusive list before a hash map insertion. If the insertion fails due to a duplicate key, the object is destroyed but the dangling pointer remains in the list. This can be triggered by a float precision flaw during progressive JPEG decoding.
Affected files:
third_party/blink/renderer/platform/graphics/image_decoding_store.ccthird_party/blink/renderer/platform/graphics/image_decoding_store.hthird_party/blink/renderer/platform/image-decoders/jpeg/jpeg_image_decoder.cc
Estimated timestamp from git blame: 2024-06-29
Summary
A highly exploitable Use-After-Free (UAF) vulnerability exists in the Blink rendering engine's ImageDecodingStore. The issue occurs because a raw pointer to a newly created DecoderCacheEntry is appended to an intrusive LRU list (ordered_cache_list_) before the entry is inserted into a hash map (decoder_cache_map_). If the hash map insertion fails due to a duplicate key, the std::unique_ptr holding the entry is destroyed, but the raw pointer remains in the intrusive list.
Because the list pointers in CacheEntry are explicitly annotated with RAW_PTR_EXCLUSION, this memory is not protected by MiraclePtr (BackupRefPtr). Subsequent cache pruning operations will perform virtual method calls on the freed object, potentially leading to Remote Code Execution (RCE) in the sandboxed renderer process.
Vulnerability Details
There are two components to this vulnerability: the trigger and the UAF logic flaw.
1. The Trigger (Math Precision Loss):
In JPEGImageDecoder::DesiredScaleNumerator, an image downscale factor is calculated using a single-precision float cast ((float)max_decoded_bytes). For very large image dimensions, this cast loses precision. Consequently, a request to scale an image to a specific size (e.g., 4101x4101) can result in an actual DecodedSize() that slightly differs (e.g., 2734x2734).
When ImageDecoderWrapper::Decode attempts to find a cached decoder, it searches using the requested size (LockDecoder(4101x4101)). When it fails to find one, it decodes the image and caches the new decoder using its actual size (InsertDecoder(2734x2734)). On subsequent decode passes of the same progressive JPEG, LockDecoder misses again, causing a second attempt to insert a decoder with the same 2734x2734 key.
2. The UAF Flaw (InsertCacheInternal):
In third_party/blink/renderer/platform/graphics/image_decoding_store.cc, the InsertCacheInternal method performs the following sequence:
// 1. Appends raw pointer to the list.
ordered_cache_list_.Append(cache_entry.get());
// ...
// 2. Attempts map insertion.
cache_map->insert(key, std::move(cache_entry));
If the key already exists (as in the duplicate trigger described above), WTF::HashMap::insert returns without consuming the unique_ptr. The function returns, the unique_ptr goes out of scope, and the memory is freed. However, the raw pointer remains in ordered_cache_list_. Furthermore, heap_memory_usage_in_bytes_ is incremented prior to the insertion but never decremented on failure, causing a memory leak that can artificially force the cache to permanently prune on every subsequent decode.
Potential Exploit Scenario
Note: These are potential steps based on code analysis; our tooling does not yet execute live exploit code.
- Trigger: An attacker hosts a malicious webpage serving a progressive JPEG with extremely large dimensions, styled with CSS to a specific scale that triggers the
floatprecision loss. - Duplicate Insertion: The browser performs an initial decode of the first JPEG scan and caches the decoder. As the next scan arrives, the math mismatch causes a cache miss, resulting in a second cache insertion attempt for the same key.
- UAF Creation: The duplicate insertion fails. The second
DecoderCacheEntryis freed, leaving a dangling pointer in theordered_cache_list_intrusive list. - Heap Grooming: The attacker uses JavaScript to allocate objects of similar size in the FastMalloc partition, reclaiming the freed
DecoderCacheEntrymemory block. The attacker populates this block with controlled data, setting theuse_count_(at offset0x8) to0and pointing the vtable pointer (at offset0x0) to a controlled ROP chain. - Execution: The attacker triggers one final image decode, or the memory leak forces a
Prune(). ThePrune()method iterates over the list, encounters the dangling pointer, passes the!UseCount()check, and callsRemoveFromCacheInternal. This immediately invokes the virtual methodcache_entry->GetType(), hijacking control flow to the attacker's payload.
Suggested Fix
- Fix the UAF in
InsertCacheInternal: The logic should be inverted. Attempt thecache_map->insert()operation first. If it succeeds (i.e.,is_new_entryis true), then append the raw pointer toordered_cache_list_and incrementheap_memory_usage_in_bytes_. - Fix the Math Precision: In
JPEGImageDecoder::DesiredScaleNumerator, usedoubleinstead offloatfor intermediate calculations involvingwtf_size_t(which is a 32-bit integer) to prevent precision loss when calculating dimensions for large images.
Evaluated with Chrome root at commit: f200f57a19490707ff8bc7aa5de3cbc443a3afad
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 code appends a raw pointer to an intrusive list before attempting to insert the owning unique_ptr into a hash map; if the insertion fails (duplicate key), the unique_ptr is destroyed but the raw pointer remains in the list.
Impact
This could lead to remote code execution in the sandboxed renderer process, though the report notes that live exploit code has not been executed.
What the attacker needed
Victim visits a malicious webpage; browser processes a crafted progressive JPEG; JavaScript enabled for heap grooming
The fix
The fix should invert the logic to insert into the hash map first and only append to the list on success, and use double instead of float for intermediate calculations in DesiredScaleNumerator.
How it was found
- An attacker hosts a webpage with a progressive JPEG of extremely large dimensions, styled with CSS to trigger a float precision loss.
- The browser decodes the first scan and caches the decoder; a subsequent scan causes a cache miss due to a size mismatch, leading to a second insertion attempt with the same key.
- The duplicate insertion fails, freeing the second DecoderCacheEntry and leaving a dangling pointer in the ordered_cache_list_.
- The attacker uses JavaScript to allocate objects of similar size, reclaiming the freed memory and populating it with controlled data, including a fake vtable and use_count_ set to 0.
- A final image decode or forced Prune() triggers a virtual method call on the freed object, hijacking control flow to the attacker's payload.
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 use-after-free happens when a program frees memory but keeps a pointer to it, and later uses that pointer as if the memory were still valid. Here, a list of cached image decoders keeps a pointer to an object that gets deleted, so when the list is later processed, it calls methods on freed memory. An attacker who can control what replaces that memory could hijack 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.