File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -3108,7 +3108,11 @@ int gdImagePaletteToTrueColor(gdImagePtr src)
3108
3108
const unsigned int sy = gdImageSY (src );
3109
3109
const unsigned int sx = gdImageSX (src );
3110
3110
3111
- src -> tpixels = (int * * ) gdMalloc (sizeof (int * ) * sy );
3111
+ // Note: do not revert back to gdMalloc() below ; reason here,
3112
+ // due to a bug with a certain memory_limit INI value treshold,
3113
+ // imagepalettetotruecolor crashes with even unrelated ZendMM allocations.
3114
+ // See GH-17772 for an use case.
3115
+ src -> tpixels = (int * * ) gdCalloc (sizeof (int * ), sy );
3112
3116
if (src -> tpixels == NULL ) {
3113
3117
return 0 ;
3114
3118
}
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments