sasha           Mon Mar 12 05:57:53 2001 EDT

  Modified files:              
    /php4/ext/gd        gd.c 
  Log:
  A small fix to make the function imageloadfont portable.
  
  
Index: php4/ext/gd/gd.c
diff -u php4/ext/gd/gd.c:1.117 php4/ext/gd/gd.c:1.118
--- php4/ext/gd/gd.c:1.117      Sun Feb 25 22:06:56 2001
+++ php4/ext/gd/gd.c    Mon Mar 12 05:57:53 2001
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: gd.c,v 1.117 2001/02/26 06:06:56 andi Exp $ */
+/* $Id: gd.c,v 1.118 2001/03/12 13:57:53 sasha Exp $ */
 
 /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, 
    Cold Spring Harbor Labs. */
@@ -371,13 +371,15 @@
 
 #endif
 
+#define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 
+0x0000ff00) << 8) | ((a & 0x000000ff) << 24))
+
 /* {{{ proto int imageloadfont(string filename)
    Load a new font */
 PHP_FUNCTION(imageloadfont) 
 {
        zval **file;
        int hdr_size = sizeof(gdFont) - sizeof(char *);
-       int ind, body_size, n=0, b;
+       int ind, body_size, n=0, b, i, body_size_check;
        gdFontPtr font;
        FILE *fp;
        int issock=0, socketd=0;
@@ -425,7 +427,23 @@
                }
                RETURN_FALSE;
        }
+       i = ftell(fp);
+       fseek(fp, 0, SEEK_END);
+       body_size_check = ftell(fp) - hdr_size;
+       fseek(fp, i, SEEK_SET);
        body_size = font->w * font->h * font->nchars;
+       if (body_size != body_size_check) {
+               font->w = FLIPWORD(font->w);
+               font->h = FLIPWORD(font->h);
+               font->nchars = FLIPWORD(font->nchars);
+               body_size = font->w * font->h * font->nchars;
+       }
+       if (body_size != body_size_check) {
+               php_error(E_WARNING, "ImageFontLoad: error reading font");
+               efree(font);
+               RETURN_FALSE;
+       }
+
        font->data = emalloc(body_size);
        b = 0;
        while (b < body_size && (n = fread(&font->data[b], 1, body_size - b, fp)))



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to