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

Use after free in PDFium (CVE-2026-93382)

A regression in PDFium's OpenJPEG code left a stale pointer in the MCC record after an MCT marker reallocated the MCT array, so a crafted PDF could trigger a heap use-after-free read during JPEG2000 decoding. The report demonstrates the read; reaching the function-pointer call would require heap grooming not attempted in the PoC.

WinD39 - Huynh Dinh Vu Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 47 days

Steps to reproduce the problem

  1. Build pdfium_test with is_asan=true from pdfium main at or after f1d22ed2 ("Fix an OpenJPEG double-free on early OOM return", 2026-07-31).

  2. Run: out/asan/pdfium_test poc_mcc_uaf.pdf (attached, 1307 bytes)

  3. ASAN reports heap-use-after-free in opj_j2k_read_mco at third_party/libopenjpeg/j2k.c:6523. Reproduces 3 of 3 runs.

The same PoC on the parent revision is clean 3 of 3.

No allocation failure is needed, no special build flags, no harness. The file is an ordinary PDF holding a 657-byte JPEG2000 image, so the crash is reached through the normal render path: CPDF_ImageRenderer -> CPDF_DIB::LoadJpxBitmap -> CJPX_Decoder::StartDecode -> opj_j2k_decode.

Attached: the PoC PDF, the raw codestream, the full symbolized ASAN report, the generator script, and a written analysis.

Problem Description

Commit f1d22ed2 ("Fix an OpenJPEG double-free on early OOM return", 2026-07-31) closes an OOM-only double-free and opens a use-after-free that needs no allocation failure. Line numbers are third_party/libopenjpeg/j2k.c at that commit. The full write-up is attached.

WHAT CHANGED

The reset block in opj_j2k_copy_default_tcp_and_create_tcd() gained two lines:

9249 l_tcp->m_nb_mct_records = 0; // added 9252 l_tcp->m_nb_mcc_records = 0; // added

For MCT the count is restored one record at a time at 9296 (m_nb_mct_records += 1). That is the point of the change and it is correct. For MCC nothing restores it. Line 9252 is the only write to m_nb_mcc_records anywhere in the function.

The mcc array itself is still fully restored: malloc 9302, memcpy 9307, m_nb_max_mcc_records 9308, and the loop at 9314-9330 rebases every m_decorrelation_array and m_offset_array onto the tile's own m_mct_records. That loop is bounded by m_nb_max_mcc_records, not the live count, so the records are copied and rebased correctly while the count describing them reads 0.

WHY ONLY THE MCC SIDE BREAKS

The two siblings got identical treatment but they are not symmetric.

MCT records own separately allocated memory, so teardown at 9528-9541 walks them individually to free each m_data, bounded by the live count. Zeroing m_nb_mct_records on an early return is necessary.

MCC records own nothing: two indices, a bitfield, and two opj_mct_data_t pointers into the tile's own m_mct_records. Teardown at 9521-9525 is a single opj_free with no per-record walk. All 23 references to m_nb_mcc_records were checked and the count bounds no free anywhere. Zeroing it buys no early-return safety and costs a live invariant.

THE INVARIANT IT COSTS

m_nb_mcc_records bounds the pointer fix-up loop in opj_j2k_read_mct():

5926 new_mct_records = opj_realloc(l_tcp->m_mct_records, ...) // the array moves 5940 for (i = 0; i < l_tcp->m_nb_mcc_records; ++i) { ... rebase ... }

At 0 that loop does nothing. An MCT marker in a tile-part header that grows m_mct_records moves the array and leaves the inherited m_mcc_records[0].m_decorrelation_array pointing into the freed block. A 7-byte MCC marker with Qmcc == 0 makes that record visible again without disturbing it: the collection loop at 6223 does not run, so the resets at 6301-6302 never happen, while 6345 still increments the count. MCO then dereferences the stale pointer at 6523.

WHAT THE STALE POINTER REACHES

The ASAN crash is a 4-byte read, but every field used afterwards comes out of the freed 320-byte block:

6523 l_data_size = MCT_ELEMENT_SIZE[l_deco_array->m_element_type] * numcomps * numcomps; 6525 if (l_deco_array->m_data_size != l_data_size || !l_deco_array->m_data) return OPJ_FALSE; 6537 j2k_mct_read_functions_to_float[l_deco_array->m_element_type]( 6538 l_deco_array->m_data, p_tcp->m_mct_decoding_matrix, l_nb_elem);

Both tables have exactly four entries, MCT_ELEMENT_SIZE at 1364 and j2k_mct_read_functions_to_float at 1374, the latter being four function pointers. m_element_type is in range only because the parser masks it at creation, (l_tmp >> 10) & 3 at 5976, and that mask constrains the value written, not the value read here. So 6537 indexes a four entry function pointer table with an unmasked 32-bit value out of freed memory and calls the result, passing m_data (a raw pointer from the same block) as the source. 6558 is the same shape into j2k_mct_read_functions_to_int32, and its output reaches l_tccp->m_dc_level_shift at 6565.

The check at 6525 compares m_data_size against a size derived from m_element_type, two fields inside the same reused block, so it is satisfied by choosing them consistently.

What is demonstrated is the read at 6523. Reaching 6537 with a chosen index also needs the 320-byte allocation groomed, which the PoC does not attempt. What separates the two is heap layout rather than further validation in this code.

A/B

Same tree, same PoC, only that one function differing, forced rebuild each way:

without the two added lines 3 of 3 runs clean with them, byte identical to main 3 of 3 runs heap-use-after-free

I diffed the function against current main byte for byte before running either side, so this is not a reconstruction of the patch.

SUGGESTED FIX

Restore the count next to the existing capacity assignment, after the memcpy has already brought the records over:

9308 l_tcp->m_nb_max_mcc_records = l_default_tcp->m_nb_max_mcc_records; 9309 l_tcp->m_nb_mcc_records = l_default_tcp->m_nb_mcc_records; // add

This cannot reintroduce a double-free on the early-return path, because no free is bounded by that count.

Reporter credit: WinD39 - Huynh Dinh Vu

Additional Comments

This is a regression from the fix for bug 540817065 (pdfium commit f1d22ed2, 2026-07-31), so it is best looked at together with that change rather than as an unrelated issue. The bug it fixed needed an allocation failure; this one does not.

Attachments: poc_mcc_uaf.pdf 1307-byte PDF. Run: out/asan/pdfium_test poc_mcc_uaf.pdf poc_mcc_uaf.bin the 657-byte raw JPEG2000 codestream embedded in the above asan_full.txt full symbolized ASAN report (use / free / alloc) gen_poc.py regenerates both files from scratch crbug_openjpeg_mcc_uaf_REPORT.txt the written analysis, same content as above plus the A/B detail

Searched the tracker for openjpeg mcc and opj_j2k before filing; the only related hit is 40064846 from 2024, which is a different bug in opj_setup_decoder and already verified.

Summary

Heap use-after-free in opj_j2k_read_mco, regression from pdfium f1d22ed2

Custom Questions

Type of crash:

Renderer (PDF). Reproduced standalone in pdfium_test built with is_asan=true.

Crash state:

==1325558==ERROR: AddressSanitizer: heap-use-after-free on address 0x7cd9d36ea840 READ of size 4, 0 bytes inside a 320-byte region

#0 opj_j2k_read_mco third_party/libopenjpeg/j2k.c:6523:54 #1 opj_j2k_read_tile_header third_party/libopenjpeg/j2k.c:9874:18 #2 opj_j2k_decode_tiles third_party/libopenjpeg/j2k.c:12003:15 #3 opj_j2k_decode third_party/libopenjpeg/j2k.c:9192:33 #4 fxcodec::CJPX_Decoder::StartDecode core/fxcodec/jpx/cjpx_decoder.cpp:519:11 #5 CPDF_DIB::LoadJpxBitmap core/fpdfapi/page/cpdf_dib.cpp:597:17 #6 CPDF_DIB::CreateDecoder core/fpdfapi/page/cpdf_dib.cpp:452:22 #7 CPDF_DIB::StartLoadDIBBase core/fpdfapi/page/cpdf_dib.cpp:207:31 #8 CPDF_PageImageCache::Entry::StartGetCachedBitmap core/fpdfapi/page/cpdf_pageimagecache.cpp:283 #11 CPDF_ImageRenderer::StartLoadDIBBase core/fpdfapi/render/cpdf_imagerenderer.cpp:73:17 #13 CPDF_RenderStatus::ContinueSingleObject core/fpdfapi/render/cpdf_renderstatus.cpp:288:25 #17 FPDF_RenderPageBitmapWithColorScheme_Start fpdfsdk/fpdf_progressive.cpp:93:3 #19 main testing/pdfium_test.cc:1627:17

freed by thread T0 here: #0 realloc #1 pdfium::internal::Realloc core/fxcrt/fx_memory_pa.cpp:74:9 #2 opj_j2k_read_mct third_party/libopenjpeg/j2k.c:5926:50

previously allocated by thread T0 here: #2 opj_j2k_copy_default_tcp_and_create_tcd third_party/libopenjpeg/j2k.c:9270:49

SUMMARY: AddressSanitizer: heap-use-after-free third_party/libopenjpeg/j2k.c:6523:54 in opj_j2k_read_mco

The complete symbolized report is attached as asan_full.txt.

Reporter credit:

WinD39 - Huynh Dinh Vu

Additional Data

Category: Security
Chrome Channel: Not sure
Regression: Yes \

The original report as published on the Chromium issue tracker, by WinD39 - Huynh Dinh Vu. 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 the added reset of m_nb_mcc_records to zero in [redacted] removes the bound on the pointer fix-up loop in opj_j2k_read_mct, so an MCT marker can reallocate m_mct_records and leave an inherited MCC record's pointer dangling.

Impact

The demonstrated impact is a heap use-after-free read during PDF rendering; the report notes that reaching the function-pointer call would require heap grooming not attempted in the PoC.

What the attacker needed

Victim opens a crafted PDF; PDF contains a JPEG2000 image

The fix

The count should be restored next to the existing capacity assignment after the memcpy, which cannot reintroduce a double-free because no free is bounded by that count.

How it was found

  1. Build pdfium_test with AddressSanitizer enabled from pdfium main at or after the specified commit.
  2. Run pdfium_test on the attached PDF file.
  3. Observe the AddressSanitizer heap-use-after-free report in opj_j2k_read_mco.

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 keeps a pointer to memory it has already freed and later reads or writes through it. Here, a small PDF with a JPEG2000 image causes the decoder to free an internal array and then use an old pointer into that freed memory. The report shows a crash from reading that stale memory, but not yet a full exploit.

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 WinD39 - Huynh Dinh Vu

View all

5 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.