From dfcbfbc9f43cca3f3726e3a2770a15095168bab1 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. --- ext/gd/libgd/gdft.c | 4 ++-- ext/gd/tests/gh17373.phpt | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 ext/gd/tests/gh17373.phpt diff --git a/ext/gd/libgd/gdft.c b/ext/gd/libgd/gdft.c index 6876ca6f6b428..953da001bbe49 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 0000000000000..354cdd07362b2 --- /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)