Skip to content
Memory corruption Advisory Advanced CVE-2025-53644

GHSL-2025-057: Heap buffer write in OpenCV - CVE-2025-53644

An uninitialized pointer in OpenCV's JPEG 2000 decoder can be left with a stack garbage value when header parsing fails, and a crafted image can then cause a write to that address. An attacker could potentially achieve arbitrary heap memory overwrite and code execution.

jarlob Follow

Originally disclosed on GitHub Security Lab

An uninitialized pointer variable on stack may lead to arbitrary heap buffer write when reading crafted JPEG images.

jarlob, on GitHub Security Lab

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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

Impact

The exploitability depends on the program's stack usage, but it may lead to arbitrary memory overwrite and code execution; the write primitive has side effects that overwrite other fields.

What the attacker needed

Victim processes a crafted JPEG 2000 image; specific stack state from prior calls

The fix

The fix was merged to the 4.x branch and released in v4.12.0.

How it was found

  1. Craft a JPEG 2000 image that causes opj_j2k_read_header to fail while leaving the image pointer uninitialized.
  2. Call cv::imdecode on the crafted image data.
  3. Repeat decoding calls so that the uninitialized pointer picks up a previously freed heap address from the stack.
  4. Observe a heap-use-after-free write when the fifth decode call is made.

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 reads an image, it uses a pointer (a variable that holds a memory address) to store where the image data will go. In this case, that pointer was not set to a safe starting value, so it could contain leftover data from earlier program activity. A specially crafted image could then make the program write data to that leftover address, potentially corrupting memory and allowing an attacker to run their own code.

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 jarlob

View all

192 more disclosed reports, best first.

More from GitHub Security Lab

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.