- Notifications
You must be signed in to change notification settings - Fork8k
Fix GH-16322: imageaffine overflow on affine argument.#16334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3687,13 +3687,25 @@ PHP_FUNCTION(imageaffine) | ||
if ((zval_affine_elem = zend_hash_index_find(Z_ARRVAL_P(z_affine), i)) != NULL) { | ||
switch (Z_TYPE_P(zval_affine_elem)) { | ||
case IS_LONG: | ||
affine[i] = Z_LVAL_P(zval_affine_elem); | ||
if (affine[i] < INT_MIN || affine[i] > INT_MAX) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This guard could use | ||
zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX); | ||
RETURN_THROWS(); | ||
} | ||
break; | ||
case IS_DOUBLE: | ||
affine[i] = Z_DVAL_P(zval_affine_elem); | ||
if (affine[i] < INT_MIN || affine[i] > INT_MAX) { | ||
zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX); | ||
RETURN_THROWS(); | ||
} | ||
break; | ||
case IS_STRING: | ||
affine[i] = zval_get_double(zval_affine_elem); | ||
if (affine[i] < INT_MIN || affine[i] > INT_MAX) { | ||
zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX); | ||
RETURN_THROWS(); | ||
} | ||
break; | ||
default: | ||
zend_argument_type_error(3, "contains invalid type for element %i", i); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
GH-16322 (imageaffine overflow/underflow on affine matrix) | ||
--EXTENSIONS-- | ||
gd | ||
--INI-- | ||
memory_limit=-1 | ||
--SKIPIF-- | ||
<?phpif (PHP_INT_SIZE !=8)die('skip this test is for 64bit platforms only');?> | ||
| ||
--FILE-- | ||
<?php | ||
$matrix = [PHP_INT_MAX,1,1,1,1,1]; | ||
$src =imagecreatetruecolor(8,8); | ||
try { | ||
imageaffine($src,$matrix); | ||
}catch (\ValueError$e) { | ||
echo$e->getMessage() .PHP_EOL; | ||
} | ||
$matrix[0] =1; | ||
$matrix[3] =PHP_INT_MIN; | ||
try { | ||
imageaffine($src,$matrix); | ||
}catch (\ValueError$e) { | ||
echo$e->getMessage(); | ||
} | ||
?> | ||
--EXPECTF-- | ||
imageaffine(): Argument #2 ($affine) element 0 must be between %s and %d | ||
imageaffine(): Argument #2 ($affine) element 3 must be between %s and %d |
Uh oh!
There was an error while loading.Please reload this page.