Skip to content
Memory corruption Disclosed report Advanced

imagegammacorrect allows arbitrary write access

imagegammacorrect did not handle gamma values of opposite signs, causing an out-of-bounds write of a null byte, potentially leading to memory corruption.

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-08-02 03:46 UTC https://bugs.php.net/bug.php?id=72730

Summary

imagegammacorrect accepts two gamma values, if they don't have the same sign then the palette colors will be assigned values bigger than 0xFF, later this values are used to calculate the transparent color using the gdTrueColorAlpha macro, and a negative value will be assigned to the transparent color. This negative value is used as an index and allows writing an arbitrary null, similar to bug #72512

Patch

2016-08-10 07:16 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, the function did not validate that the two gamma values have the same sign, leading to an integer overflow and out-of-bounds write.

Impact

This could allow an attacker to write a null byte to an arbitrary memory location, potentially causing memory corruption.

What the attacker needed

Ability to call imagegammacorrect with crafted gamma values

The fix

The issue 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.

The imagegammacorrect function takes two gamma values. If one is positive and the other negative, it miscalculates and writes a null byte outside the intended memory area, which can crash the program.

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.