Skip to content
Memory corruption Advisory Advanced CVE-2026-5287

Use after free in PDF (CVE-2026-5287)

A PDF viewer's ink annotation code unpinned a page from memory when the last user stroke was discarded, even though cached shape handles for that page were still held. After the page unloaded, a later Undo passed a freed page-object handle to a PDFium call, causing a use-after-free in the renderer.

Syn4pse Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 11 days

Summary

DiscardStroke() erases stroked_pages_unload_preventers_[page_index] when no ink_stroke_data_ entries remain for that page, without checking whether ink_modeled_shape_map_ still holds FPDF_PAGEOBJECT handles cached by LoadV2InkPathsForPage(). Once unpinned, the page can unload and free the underlying page-object storage. A subsequent Undo calls UpdateShapeActive(), which passes the now-dangling handle to FPDFPageObj_SetIsActive(), resulting in a renderer UAF.

Details

LoadV2InkPathsForPage() caches raw FPDF_PAGEOBJECT handles in ink_modeled_shape_map_ and pins the page via stroked_pages_unload_preventers_ so those handles stay valid:

C++
PDFiumEngine::LoadV2InkPathsForPage(int page_index) {
...
  for (auto& read_result : read_results) {
    InkModeledShapeId id(next_ink_modeled_shape_id_++);
    page_shape_map[id] = std::move(read_result.shape);
    ink_modeled_shape_map_[id] = read_result.page_object; // cache raw handle
  }

...
  CHECK(!stroked_pages_unload_preventers_.contains(page_index));

...
  if (!page_shape_map.empty()) {
    stroked_pages_unload_preventers_.insert(
        {page_index, PDFiumPage::ScopedUnloadPreventer(page)}); // pin page
  }
}

DiscardStroke() removes the unload preventer by checking only ink_stroke_data_, never ink_modeled_shape_map_:

C++
void PDFiumEngine::DiscardStroke(int page_index, InkStrokeId id) {
  CHECK(PageIndexInBounds(page_index));
  auto it = ink_stroke_data_.find(id);
  CHECK(it != ink_stroke_data_.end());
  for (FPDF_PAGEOBJECT page_object : it->second.page_objects) {
    bool result =
        FPDFPage_RemoveObject(pages_[page_index]->GetPage(), page_object);
    CHECK(result);

    // FPDFPage_RemoveObject() transferred ownership of `page_object` to the
    // caller. Free it since `page_object` is being discarded.
    FPDFPageObj_Destroy(page_object);
  }
  ink_stroke_data_.erase(it);

  bool page_still_has_strokes =
      std::ranges::any_of(ink_stroke_data_, [page_index](const auto& it) {
        return it.second.page_index == page_index;
      });
  if (!page_still_has_strokes) {
    stroked_pages_unload_preventers_.erase(page_index);  // <-- bug: ignores loaded V2 shapes
  }
}

ApplyUndoRedoDiscards() calls DiscardStroke for every stroke in the discarded redo tail. When the discarded stroke is the last user-added stroke on a page that still has preloaded V2 ink, the unload preventer is removed while ink_modeled_shape_map_ still holds cached handles.

Once unpinned, scrolling the page off-screen frees the underlying page-object storage. A subsequent Undo walks loaded_v2_shapes_ into UpdateShapeActive(), which forwards the now-dangling handle to FPDFPageObj_SetIsActive(), leading to the UAF:

C++
void PDFiumEngine::UpdateShapeActive(int page_index,
                                     InkModeledShapeId id,
                                     bool active) {
  auto it = ink_modeled_shape_map_.find(id);
  bool result = FPDFPageObj_SetIsActive(it->second, active); // stale handle
}

Bisection

This issue is introduced by the commit https://chromium-review.googlesource.com/c/chromium/src/+/5997152, which introduce the vulnerable LoadV2InkPathsForPage function.

Reproduction

Download chrome from https://storage.googleapis.com/chromium-browser-asan/linux-release/asan-linux-release-1602931.zip

Put the background.js, manifest.json, test.pdf under a directory as an extension.

Run with

Bash
./chrome --load-extension=/path/to/ext --no-sandbox --window-size=900,420 about:blank

You would observe the UAF shown in asan.txt

NOTE that we need the --window-size=900,420, since we hardcode the scroll down length in the extension. If we run against other window size, it needs the adjustment of the POC extension accordingly.

This is also reproducible manually: open the bundled test.pdf in Chrome, enter draw mode (which loads the V2 ink paths), draw a stroke then Ctrl+Z, switch to eraser and make any erase gesture, scroll page 1 out of view, then Ctrl+Z. The extension automates the above sequence. Hence you just need to put three attached POC files under an extension directory.

Suggested Fix

chrome_pdf::PDFiumEngine::DiscardStroke() should only erase stroked_pages_unload_preventers_[page_index] when the page has neither remaining ink_stroke_data_ entries nor any loaded V2 shapes still represented in ink_modeled_shape_map_ / loaded_v2_shapes_.

We should also reject tale cached shape handles before chrome_pdf::PDFiumEngine::UpdateShapeActive() calls FPDFPageObj_SetIsActive(), so page unload cannot leave a dangling FPDF_PAGEOBJECT behind.

The original report as published on the Chromium issue tracker, by Syn4pse. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

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 DiscardStroke() removed the page's unload preventer based only on remaining ink_stroke_data_ entries, ignoring cached FPDF_PAGEOBJECT handles still held in ink_modeled_shape_map_.

Impact

A renderer use-after-free occurs, which could crash the browser and may be exploitable for code execution, though the text only demonstrates the crash under ASan.

What the attacker needed

Chrome with PDF ink support; User draws and undoes strokes; Page scrolled out of view

The fix

DiscardStroke() should only erase the unload preventer when the page has neither remaining strokes nor loaded V2 shapes, and UpdateShapeActive() should reject stale cached handles before calling into PDFium.

How it was found

  1. Open the bundled PDF in Chrome and enter draw mode so V2 ink paths load.
  2. Draw a stroke, then press Ctrl+Z.
  3. Switch to the eraser and make an erase gesture.
  4. Scroll page 1 out of view so the page unloads.
  5. Press Ctrl+Z again to trigger the use-after-free.

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 you draw on a PDF in Chrome, the browser keeps some internal references to shapes on the page so it can redraw them. A cleanup routine removed a 'keep this page in memory' marker too early, so the page and its shapes were freed while references to them still existed. Using those stale references later (via Undo) touches freed memory, which can crash the browser and, in principle, be exploited.

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 by Syn4pse

View all

13 more disclosed reports, best first.

More from Google Chrome

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.