Skip to content
Memory corruption Disclosed report Advanced

imagescale out-of-bounds read

Bicubic scaling in PHP's bundled GD read past the end of a weights array when the channel index equalled the window size, causing invalid memory access.

fms Follow

Originally disclosed on HackerOne

Bounty$500 View original
  • Fixed in 5 days
  • Paid in 5 days
  • Disclosed after 3.4 years

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

Invalid memory access while applying bicubic scaling on images.

Reading symbols from /home/user/php-7.0/sapi/cli/php...done.
(gdb) b gd_interpolation.c:890
Breakpoint 1 at 0x81925a9: file /home/user/php-7.0/ext/gd/libgd/gd_interpolation.c, line 890.
(gdb) b gd_interpolation.c:982 if i == 12
Breakpoint 2 at 0x81929fc: file /home/user/php-7.0/ext/gd/libgd/gd_interpolation.c, line 982.
(gdb) r
Starting program: /home/user/php-7.0/sapi/cli/php -n phuzz4.php

Breakpoint 1, _gdContributionsAlloc (line_length=13, windows_size=9) at /home/user/php-7.0/ext/gd/libgd/gd_interpolation.c:890
890         res->ContribRow = (ContributionType *) gdMalloc(line_length * sizeof(ContributionType));

# windows_size is 9 

(gdb) c
Continuing.

Breakpoint 2, _gdScaleRow (pSrc=0x8c71c38, src_width=100, dst=0x8c7f5f0, dst_width=13, row=0, contrib=0x8c5c2d8)
    at /home/user/php-7.0/ext/gd/libgd/gd_interpolation.c:982
982                 r += (unsigned char)(contrib->ContribRow[x].Weights[left_channel] * (double)(gdTrueColorGetRed(p_src_row[i])));
(gdb) p left_channel
$1 = 9

contrib->ContribRow[x].Weights[left_channel] tries to access 10th element but the size is 9.

This affected PHP version 5.5, 5.6 and 7.0, patch released today:

http://php.net/ChangeLog-5.php#5.5.36

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

Impact

The out-of-bounds read causes invalid memory access when bicubic scaling is applied; the text does not show crash, memory exposure or code execution.

What the attacker needed

Ability to trigger bicubic scaling on an image

The fix

The bug was fixed in a patch released for PHP 5.5, 5.6 and 7.0.

How it was found

  1. Build PHP with debug symbols and run a fuzzing script under gdb.
  2. Set a breakpoint in the contribution allocation function and observe the window size.
  3. Set a conditional breakpoint in the row scaling function when the loop index reaches 12.
  4. Inspect the channel index and see it equals the window size, exceeding the array bounds.

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 PHP resizes an image, it blends neighbouring pixels using a small table of weights. The code used an index one too large, reading just past the end of the table.

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.