From ec90367cd8bf48861325bb2b75971825983e3887 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 6 Jan 2025 02:00:11 +0100 Subject: [PATCH] Fix GH-17373: imagefttext() ignores clipping rect for palette images We apply the same fix that has been applied to external libgd at least as of 2.0.29. To avoid issues regarding minor FreeType rendering differences, the test case does not compare against an image, but rather checks that all pixels outside the clipping rect have the background color. Closes GH-17374. --- NEWS | 2 ++ ext/gd/libgd/gdft.c | 4 ++-- ext/gd/tests/gh17373.phpt | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 ext/gd/tests/gh17373.phpt diff --git a/NEWS b/NEWS index 922452e4bf6..a1e5a2cb247 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,8 @@ PHP NEWS - GD: . Fixed bug GH-17349 (Tiled truecolor filling looses single color transparency). (cmb) + . Fixed bug GH-17373 (imagefttext() ignores clipping rect for palette + images). (cmb) - Intl: . Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos) diff --git a/ext/gd/libgd/gdft.c b/ext/gd/libgd/gdft.c index 6876ca6f6b4..953da001bbe 100644 --- a/ext/gd/libgd/gdft.c +++ b/ext/gd/libgd/gdft.c @@ -720,7 +720,7 @@ static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, y = pen_y + row; /* clip if out of bounds */ - if (y >= im->sy || y < 0) { + if (y > im->cy2 || y < im->cy1) { continue; } @@ -743,7 +743,7 @@ static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, x = pen_x + col; /* clip if out of bounds */ - if (x >= im->sx || x < 0) { + if (x > im->cx2 || x < im->cx1) { continue; } /* get pixel location in gd buffer */ diff --git a/ext/gd/tests/gh17373.phpt b/ext/gd/tests/gh17373.phpt new file mode 100644 index 00000000000..354cdd07362 --- /dev/null +++ b/ext/gd/tests/gh17373.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug GH-17373 (imagefttext() ignores clipping rect for palette images) +--EXTENSIONS-- +gd +--FILE-- + +--EXPECT-- +int(0)