Skip to content

Commit ed18fd0

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
2 parents 5b87faa + 4d7d01d commit ed18fd0

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ PHP NEWS
3030
. Fixed bug GH-17643 (FPM with httpd ProxyPass encoded PATH_INFO env).
3131
(Jakub Zelenka)
3232

33+
- GD:
34+
. Fixed bug GH-17772 (imagepalettetotruecolor crash with memory_limit=2M).
35+
(David Carlier)
36+
3337
- LDAP:
3438
. Fixed bug GH-17704 (ldap_search fails when $attributes contains a
3539
non-packed array with numerical keys). (nielsdos, 7u83)

ext/gd/libgd/gd.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -3162,7 +3162,11 @@ int gdImagePaletteToTrueColor(gdImagePtr src)
31623162
const unsigned int sy = gdImageSY(src);
31633163
const unsigned int sx = gdImageSX(src);
31643164

3165-
src->tpixels = (int **) gdMalloc(sizeof(int *) * sy);
3165+
// Note: do not revert back to gdMalloc() below ; reason here,
3166+
// due to a bug with a certain memory_limit INI value treshold,
3167+
// imagepalettetotruecolor crashes with even unrelated ZendMM allocations.
3168+
// See GH-17772 for an use case.
3169+
src->tpixels = (int **) gdCalloc(sizeof(int *), sy);
31663170
if (src->tpixels == NULL) {
31673171
return 0;
31683172
}

ext/gd/tests/gh17772.phpt

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-17772 (imagepalettetotruecolor segfault on image deallocation)
3+
--EXTENSIONS--
4+
gd
5+
--INI--
6+
memory_limit=2M
7+
--CREDITS--
8+
YuanchengJiang
9+
--SKIPIF--
10+
<?php
11+
if (!GD_BUNDLED) die("skip requires bundled GD library");
12+
?>
13+
--FILE--
14+
<?php
15+
function setStyleAndThickness($im, $color, $thickness)
16+
{
17+
$arr = [];
18+
$i = 0;
19+
while ($i < 16 * $thickness) {
20+
$arer[$i++] = $color;
21+
}
22+
}
23+
$im = imagecreate(800, 800);
24+
setStyleAndThickness($im, 0, 6);
25+
imagepalettetotruecolor($im);
26+
?>
27+
--EXPECTF--
28+
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d

0 commit comments

Comments
 (0)