imagesettile() and imagesetbrush() keep a dangling pointer once the tile is freed
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Description
imagesettile() passes the libgd pointer of the tile to gdImageSetTile() without keeping a reference to the tile object. Once the tile GdImage is freed, the image keeps a dangling pointer, and the next fill with IMG_COLOR_TILED reads freed memory. imagesetbrush() has the same shape, with IMG_COLOR_BRUSHED.
The following code:
<?php
$canvas = imagecreatetruecolor(100, 100);
(function () use ($canvas) {
$tile = imagecreatetruecolor(10, 10);
imagesettile($canvas, $tile);
})();
// The tile is freed: its memory is reused
$strings = [];
for ($i = 0; $i < 10000; ++$i) {
$strings[] = str_repeat("\xff", 7000 + $i % 64);
}
imagefilledrectangle($canvas, 0, 0, 99, 99, IMG_COLOR_TILED);
echo "survived\n";
Resulted in this output:
Segmentation fault
But I expected this output instead:
survived
It crashes every time on PHP 8.5.12 (macOS, system libgd 2.3.3) and on PHP 8.4.27 (the php:8.4-cli Docker image, bundled GD). The same script with imagesetbrush() and imageline(..., IMG_COLOR_BRUSHED) also crashes on 8.5.12.
In ext/gd/gd.c on master, PHP_FUNCTION(imagesettile) and PHP_FUNCTION(imagesetbrush) only call gdImageSetTile(im, tile) and gdImageSetBrush(im, tile), and php_gd_image_object has no field that would hold the tile or the brush. A fix could keep a reference to the tile and brush objects in php_gd_image_object, released when they are replaced and when the image is freed (and reported by get_gc).
I found it while drawing SVG patterns with GD in a userland library: keeping the tile in a variable until the drawing ends works around it.
PHP Version
PHP 8.5.12 (cli) (ZTS)
PHP 8.4.27 (cli) (php:8.4-cli Docker image)
Operating System
macOS 27; Debian (Docker)
- Lingua principale
- C
- Stelle
- 41.8k
- Fork
- 8.5k
- Merge medio
- 2g 12h
- PR unite (30g)
- 137
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di php/php-src
-
SNMP accepts malformed remote portsForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
php/php-src#25137 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
quoted_printable_encode() produces lines longer than 76 characters for bytes 0xF5 to 0xFFForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
php/php-src#24196 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Feature Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
php/php-src#24183 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
research-radar
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
good first issue help wanted program
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
hffgzktbcc-blip/ounce-core#297 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
virtualsquare/picotcp#88 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno