Re: [PHP-DEV] Bug #597: imagettfbbox dumps core From: John Ellson (ellson <email protected>)
Date: 07/30/98

webmaster <email protected> wrote:
>
> From: webmaster <email protected>
> Operating system: Linux 2.1.35 libc5
> PHP version: 3.0.2a
> PHP Bug Type: Reproduceable crash
> Bug description:
> $bbox = ImageTTFBBox(20, 0, "/home/httpd/fonts/arial.ttf", "Any text goes here");
>
> The server dumps core. I tried gd 1.2 and 1.3. I also tried libttf 1.0 and 1.1.
>
> My box is a redhat 4.2. I use apache 1.2.

I think this patch to functions/gd.c should fix the problem (also Bug
#559).

I already sent this patch to Stig and Rasmus but I guess
they must be swamped.

John Ellson

*** gd.c.orig Mon Jul 27 23:46:33 1998
--- gd.c Tue Jul 28 00:01:15 1998
***************
*** 1539,1546 ****
          convert_to_string(FONTNAME);
          convert_to_string(C);
          if (mode == TTFTEXT_BBOX) {
! IM->type = IS_LONG;
! IM->value.lval = -1;
                  col = x = y = -1;
          } else {
                  convert_to_long(X);
--- 1539,1545 ----
          convert_to_string(FONTNAME);
          convert_to_string(C);
          if (mode == TTFTEXT_BBOX) {
! im = NULL;
                  col = x = y = -1;
          } else {
                  convert_to_long(X);
***************
*** 1550,1555 ****
--- 1549,1559 ----
                  col = COL->value.lval;
                  y = Y->value.lval;
                  x = X->value.lval;
+ im = php3_list_find(IM->value.lval, &ind_type);
+ if (!im || ind_type != GD_GLOBAL(le_gd)) {
+ php3_error(E_WARNING, "Unable to find image pointer");
+ RETURN_FALSE;
+ }
          }
  
          ptsize = PTSIZE->value.dval;
***************
*** 1558,1573 ****
          string = (unsigned char *) C->value.str.val;
          l = strlen(string);
          fontname = (unsigned char *) FONTNAME->value.str.val;
-
- if (mode == TTFTEXT_BBOX) {
- im = NULL;
- } else {
- im = php3_list_find(IM->value.lval, &ind_type);
- if (!im || ind_type != GD_GLOBAL(le_gd)) {
- php3_error(E_WARNING, "Unable to find image pointer");
- RETURN_FALSE;
- }
- }
  
          error = gdttf(im, brect, col, fontname, ptsize, angle, x, y, string);
  
--- 1562,1567 ----