Skip to content
Memory corruption Disclosed report Advanced

select_colors write out-of-bounds

A type mismatch between a 64-bit and 32-bit integer parameter in the palette conversion function caused a large value to be truncated to zero, leading to insufficient memory allocation and an out-of-bounds write.

fms Follow

Originally disclosed on HackerOne

Bounty$1,000 View original
  • Fixed in 32 days
  • Paid in 32 days
  • Disclosed after 3.2 years

Upstream Bug

2016-07-28 06:38 UTC https://bugs.php.net/bug.php?id=72697

Summary

Type mismatch parameters between ncolors and colorsWanted parameters at zif_imagetruecolortopalette and php_gd_gdImageTrueColorToPalette, ncolors is a 64 bit integer and colorsWanted is 32 bits, ncolors' value 0x1000000000000000 becomes 0 inside php_gd_gdImageTrueColorToPalette. Later, select_colors will not allocate enough memory and writes out of bounds.

Patch

2016-08-10 07:01 UTC http://git.php.net/?p=php-src.git;a=commit;h=4d76676101f8814520ea988e42b3bda54eb9e255

Fixed for PHP 5.6.25, PHP 7.0.10

http://php.net/ChangeLog-5.php http://php.net/ChangeLog-7.php#7.0.10

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 a type mismatch where a 64-bit integer parameter was passed to a function expecting a 32-bit integer, causing truncation to zero and subsequent under-allocation.

Impact

An attacker could cause an out-of-bounds write.

What the attacker needed

PHP with the imagetruecolortopalette function

The fix

The bug was fixed in PHP 5.6.25 and PHP 7.0.10.

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.

This bug is in a PHP function that converts images to a palette format. A number too big for the function got cut down to zero, so it didn't reserve enough memory and wrote past the end of it.

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.