Skip to content
Memory corruption Write-up Advanced

Analysis of CVE-2013-0809 – Java integer overflow

An integer overflow in the Java AWT MediaLib component's image allocation allowed a crafted image to cause a heap buffer overflow. An attacker could exploit this to overwrite memory and potentially hijack execution flow, as demonstrated by a proof-of-concept that crashed the JVM with a controlled instruction pointer.

axtaxt.wordpress.com

Published on axtaxt.wordpress.com

This post is about the analysis of CVE-2013-0809, a java security bug I’ve found. As it is common for java bugs, the most relevant information can be found in RedHat’s CVE database and in RedHat’s bugzilla.

The author, on axtaxt.wordpress.com

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 write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The mlib_ImageCreate function did not check for integer overflow when calculating the allocation size as width * height * channels, allowing a small buffer to be allocated and then overflowed during data copy.

Impact

An attacker could cause a heap overflow and potentially execute arbitrary code, though the proof-of-concept only demonstrated a crash with a controlled instruction pointer on Java 1.6 32-bit Linux; Java 1.7 has DEP enabled by default, which may hinder exploitation.

What the attacker needed

Java 1.6 on 32-bit Linux; Ability to run Java code (e.g., applet)

The fix

The vulnerability was fixed by adding an overflow check in the mlib_ImageCreate function, as indicated by the linked OpenJDK patch.

How it was found

  1. Create a custom SampleModel subclass that passes constructor checks with small width and height, then overwrites those fields with large values to cause overflow.
  2. Use a negative scanlineStride to satisfy DataBuffer size validation.
  3. Call ConvolveOp.filter with a crafted BufferedImage to reach the vulnerable native code.
  4. Allocate Inflater objects to shape the heap and place a victim object after the overflowing allocation.
  5. Trigger the overflow via getRGB to overwrite the z_free pointer in the victim Inflater's z_stream structure.
  6. Call end() on the victim Inflater to hijack execution flow, resulting in a crash at the controlled address.

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 write-up has not been written yet. The Original tab links to the source.

This report describes a bug in Java's image processing code. When Java calculates how much memory to allocate for an image, it multiplies the image's width, height, and number of colour channels. If those numbers are chosen carefully, the multiplication can overflow, meaning the result wraps around to a small number. Java then allocates a tiny buffer but later writes much more data into it, corrupting other memory. The author shows how to reach this code from normal Java image operations and how to turn the corruption into a crash with a controlled address.

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.

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.