Skip to content
Memory corruption Disclosed report Advanced

imagegif/output out-of-bounds access

The output function in gd_gif_out.c could access the masks array out of bounds when ctx->cur_bits became negative while generating a GIF file, potentially causing a crash or undefined behaviour.

fms Follow

Originally disclosed on HackerOne

Bounty$500 View original
  • Fixed in 11 days
  • Paid in 11 days
  • Disclosed after 3.2 years

Bug https://bugs.php.net/bug.php?id=72519

Summary output function from gd_gif_out.c causes out-of-bounds access of the masks array when ctx->cur_bits becomes a negative number while generating a gif file.

Reported to PHP 2016-06-30 04:10 UTC

Patch 2016-07-19 07:47 UTC http://git.php.net/?p=php-src.git;a=commit;h=8dc5ffa479f886fae235d4ff6391e14546a3fda9

Fixed for PHP 5.5 (security only mode), PHP 5.6, PHP 7.0 http://php.net/ChangeLog-5.php http://php.net/ChangeLog-7.php

The original report as published on HackerOne, by fms. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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 code did not check that ctx->cur_bits stayed non-negative before using it as an index into the masks array.

Impact

This could lead to a crash or potentially other undefined behaviour when a GIF is generated with the problematic state.

What the attacker needed

Ability to trigger GIF output with negative cur_bits

The fix

The issue was fixed in PHP 5.5, 5.6 and 7.0 via a patch.

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 creates a GIF image, it packs data into a special format. A counter that tracks how many bits are left to process could become negative, and the program then reads from a list of masks using that negative number as an index. That reads outside the list, which is a memory safety bug that can crash the program or worse.

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 fms

View all

33 more disclosed reports, best first.

More from Internet Bug Bounty

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.