Skip to content
Memory corruption Disclosed report Advanced

Illegal write/read access caused by gdImageAALine overflow

An integer overflow in the line-clipping calculation of gdImageAALine leads to illegal write/read access in gdImageSetAAPixelColor. An attacker could potentially cause memory corruption by drawing a specially crafted line.

fms Follow

Originally disclosed on HackerOne

Bounty$500 Low View original
  • Fixed in 18 days
  • Paid in 18 days
  • Disclosed after 3.0 years

Upstream Bug

https://bugs.php.net/bug.php?id=72482

Summary

Ilegal write/read access at gdImageSetAAPixelColor caused by gdImageAALine overflow. gdImageAALine tries to clip the limit values and fails because an integer overflow occurs while calculating the new line limits.

PHP 5 is affected, but my debugging is done on PHP 7.

One of the integer overflows happens here:

1314 x2 -= ((im->sy - y2) * (x1 - x2)) / (y2 - y1); gdb-peda$ p ((im->sy - y2) * (x1 - x2)) / (y2 - y1) ## (a * b) / c fails $8 = 0x0 gdb-peda$ p (im->sy - y2) * ((x1 - x2) / (y2 - y1)) ## a * (b / c) works $9 = 0x40000c10

The illegal write access happens while trying to set this pixels to draw the line in gdImageSetAAPixelColor:

Patch

http://git.php.net/?p=php-src.git;a=commit;h=b25009fc2c97c6b5a93b3fc5f6a5b221b62f1273
https://gist.github.com/anonymous/873314feb4f89bd8336711333299f748

Fixed for PHP 5.6.28, PHP 7.0.13

http://php.net/ChangeLog-5.php#5.6.28 http://php.net/ChangeLog-7.php#7.0.13

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 an integer overflow in the calculation of new line limits when clipping, due to the order of operations in the expression.

Impact

Could lead to illegal memory write/read, potentially causing a crash.

What the attacker needed

Ability to draw a line with gdImageAALine

The fix

The bug was fixed in PHP 5.6.28 and PHP 7.0.13.

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 image library's line-drawing function tries to keep the line within the image boundaries, but a maths mistake causes a number to wrap around and become huge. This makes the program write to memory outside the intended area, which can crash or corrupt data.

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.