diff options
| author | Alexander Feldman <sasha@php.net> | 2001-03-12 13:57:53 +0000 |
|---|---|---|
| committer | Alexander Feldman <sasha@php.net> | 2001-03-12 13:57:53 +0000 |
| commit | 179165811292ac5f7bac9b92b36fb2af914772ee (patch) | |
| tree | fa4527f2702a6ade466b16388968bb00355dee1a | |
| parent | 0fa068e1fa629f4421a8f8f4306c2931df852a3f (diff) | |
| download | php-git-179165811292ac5f7bac9b92b36fb2af914772ee.tar.gz | |
A small fix to make the function imageloadfont portable.
| -rw-r--r-- | ext/gd/gd.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 5560e4b182..05b1c9521f 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -371,13 +371,15 @@ gdImageColorResolve(gdImagePtr im, int r, int g, int b) #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 @@ PHP_FUNCTION(imageloadfont) } 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))) |
