com php-src: imageloadfont: Perform overflow check before calculation: ext/gd/gd.c
| From: | Nikita Popov | Date: | Wed, 19 Jun 2019 13:50:52 +0000 |
| Subject: | com php-src: imageloadfont: Perform overflow check before calculation: ext/gd/gd.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106915@lists.php.net to get a copy of this message | ||
Commit: 88b603768f8e5074ad5cbdccc1e0779089fac9d0
Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 19 Jun 2019 15:50:52 +0200
Parents: 2a9fc310211eb0ed5ee2b2954a57c49c17c7e6a7
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=88b603768f8e5074ad5cbdccc1e0779089fac9d0
Log:
imageloadfont: Perform overflow check before calculation
Instead of afterwards...
Changed paths:
M ext/gd/gd.c
Diff:
diff --git a/ext/gd/gd.c b/ext/gd/gd.c
index eb6a3fc..1ae52c6 100644
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -1443,6 +1443,13 @@ PHP_FUNCTION(imageloadfont)
body_size_check = php_stream_tell(stream) - hdr_size;
php_stream_seek(stream, i, SEEK_SET);
+ if (overflow2(font->nchars, font->h) || overflow2(font->nchars * font->h, font->w
)) {
+ php_error_docref(NULL, E_WARNING, "Error reading font, invalid font header");
+ efree(font);
+ php_stream_close(stream);
+ RETURN_FALSE;
+ }
+
body_size = font->w * font->h * font->nchars;
if (body_size != body_size_check) {
font->w = FLIPWORD(font->w);
@@ -1451,13 +1458,6 @@ PHP_FUNCTION(imageloadfont)
body_size = font->w * font->h * font->nchars;
}
- if (overflow2(font->nchars, font->h) || overflow2(font->nchars * font->h, font->w
)) {
- php_error_docref(NULL, E_WARNING, "Error reading font, invalid font header");
- efree(font);
- php_stream_close(stream);
- RETURN_FALSE;
- }
-
if (body_size != body_size_check) {
php_error_docref(NULL, E_WARNING, "Error reading font");
efree(font);