Skip to content
Memory corruption Advisory Advanced CVE-2017-14441

Simple DirectMedia Layer SDL2_image ICO Pitch Handling Code Execution Vulnerability

An integer overflow in SDL2_image's ICO parsing leads to a heap buffer overflow, allowing an attacker to execute code by displaying a crafted ICO image.

Lilith >_> Follow

Originally disclosed on Cisco Talos

High 8.8 View original

An exploitable code execution vulnerability exists in the ICO image rendering functionality of SDL2image-2.0.2. A specially crafted ICO image can cause an integer overflow, cascading to a heap overflow resulting in code execution.

Lilith <(x_x)>, 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

Likely the pitch calculation multiplies width by bytes per pixel without checking for integer overflow, and the resulting pitch is used to allocate a buffer while the width is used unchecked in a write loop.

Impact

An attacker could execute arbitrary code by convincing a victim to display a specially crafted ICO image.

What the attacker needed

Victim opens a crafted ICO image

The fix

The pitch calculation should check for integer overflow and validate the width before using it in memory operations.

How it was found

  1. Craft an ICO file with a BITMAPINFOHEADER where biWidth is set to a large value that causes an integer overflow when multiplied by BytesPerPixel.
  2. Set the pixel format such that BytesPerPixel is large enough to trigger the overflow.
  3. Open the crafted ICO file with an application using SDL2_image, causing the library to allocate a small buffer due to the overflow.
  4. The library then writes pixel data using the unchecked width, overflowing the heap buffer and corrupting adjacent memory.

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 the library loads an ICO image, it calculates how much memory to allocate based on the image's width and other properties. If those values are chosen maliciously, the calculation can wrap around to a small number, so a small buffer is allocated. Later, the library writes pixel data using the original large width, overflowing the buffer and letting an attacker control memory, which can lead to running arbitrary 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 Lilith >_>

View all

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