Skip to content
Memory corruption Advisory Advanced CVE-2019-5064

OpenCV JSON persistence parser buffer overflow vulnerability

A heap buffer overflow exists in OpenCV's JSON persistence parser when a null byte is encountered, causing the entire value up to that point to be copied into a fixed-size buffer without a length check. An attacker could provide a specially crafted JSON file to trigger heap corruption and potentially achieve code execution.

Dave McDaniel Follow

Originally disclosed on Cisco Talos

High 8.8 View original

An exploitable heap buffer overflow vulnerability exists in the data structure persistence functionality of OpenCV, version 4.1.0. A specially crafted JSON file can cause a buffer overflow, resulting in multiple heap corruptions and potentially code execution.

Dave McDaniel, on Cisco Talos

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

Root cause

The parser copies a JSON value into a fixed-size heap buffer without verifying that the value length fits, leading to a heap overflow.

Impact

The overflow corrupts heap memory and can lead to arbitrary free() and potentially code execution.

What the attacker needed

Victim opens a crafted JSON file

The fix

The vendor patched the vulnerability in December 2019.

How it was found

  1. Create a JSON file with a value longer than the buffer size.
  2. Load the file using OpenCV's FileStorage in read mode.
  3. The parser copies the oversized value into the fixed buffer, causing a heap overflow.

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.

OpenCV is a library for image processing. It can save and load data structures in JSON files. A bug in the JSON parser means that if a file contains a very long value, the program copies it into a fixed-size memory area without checking the length, overwriting other memory. This can crash the program or let an attacker 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 Dave McDaniel

View all

23 more disclosed reports, best first.

More from Cisco Talos

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.