imagefilltoborder stackoverflow on truecolor images
An invalid colour value passed to the imagefilltoborder function causes infinite recursion in the GD library when the image is truecolor, leading to stack exhaustion. An attacker could crash the PHP process by supplying a crafted colour argument.
- Fixed in 56 days
- Paid in 56 days
- Disclosed after 56 days
Upstream Bug
https://bugs.php.net/bug.php?id=72696
Summary
Invalid color causes stack exhaustion by recursive call to function gdImageFillToBorder when the image used is truecolor. This was tested on a 64 bits platform.
GDB debugging
gdb -q --args /home/operac/php-70-sinasan/sapi/cli/php -n poc.php
Reading symbols from /home/operac/php-70-sinasan/sapi/cli/php...done.
(gdb) b gd.c:1851
Breakpoint 1 at 0x54a354: gd.c:1851. (2 locations)
(gdb) b gd.c:1834
Breakpoint 2 at 0x54a287: gd.c:1834. (2 locations)
(gdb) r
Starting program: /home/operac/php-70-sinasan/sapi/cli/php -n poc.php
Breakpoint 1, php_gd_gdImageFillToBorder (im=0x7ffff2c77000, x=0, y=0, border=1, color=-2) at /home/operac/php-70-sinasan/ext/gd/libgd/gd.c:1851
1851 gdImageFillToBorder(im, i, y + 1, border, color);
(gdb) c
Continuing.
Breakpoint 2, php_gd_gdImageFillToBorder (im=0x7ffff2c77000, x=0, y=1, border=1, color=-2) at /home/operac/php-70-sinasan/ext/gd/libgd/gd.c:1834
1834 gdImageFillToBorder(im, i, y - 1, border, color);
(gdb) c
Continuing.
Breakpoint 1, php_gd_gdImageFillToBorder (im=0x7ffff2c77000, x=0, y=0, border=1, color=-2) at /home/operac/php-70-sinasan/ext/gd/libgd/gd.c:1851
1851 gdImageFillToBorder(im, i, y + 1, border, color);
(gdb) c
Continuing.
Breakpoint 2, php_gd_gdImageFillToBorder (im=0x7ffff2c77000, x=0, y=1, border=1, color=-2) at /home/operac/php-70-sinasan/ext/gd/libgd/gd.c:1834
1834 gdImageFillToBorder(im, i, y - 1, border, color);
(gdb) p/x color
$1 = 0xfffffffe
Patch
https://github.com/php/php-src/commit/863d37ea66d5c960db08d6f4a2cbd2518f0f80d1
Fixed for PHP 5.6.28
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
Impact
An attacker could cause a denial of service by crashing the PHP process through stack exhaustion.
What the attacker needed
Ability to call imagefilltoborder with a truecolor image; invalid colour value
The fix
The issue was fixed in PHP 5.6.28 by a patch.
How it was found
- Create a truecolor image.
- Call imagefilltoborder with an invalid colour value.
- Observe the recursive calls and stack exhaustion.
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 imagefilltoborder function fills an area of an image up to a border colour. If you give it a colour value that is not valid, the function keeps calling itself over and over until the program runs out of memory for function calls (the stack) and crashes. This means a bad input can take down the whole PHP process.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.