Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected value in ext/gd/libgd/gd_interpolation.c:2443 #16322

Closed
YuanchengJiang opened this issue Oct 9, 2024 · 2 comments
Closed

Unexpected value in ext/gd/libgd/gd_interpolation.c:2443 #16322

YuanchengJiang opened this issue Oct 9, 2024 · 2 comments

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
$matrix = [PHP_INT_MAX, 1, 1, 1, 1, 1];
$src = imagecreatetruecolor(8, 8);
var_dump(imageaffine($src, $matrix));

Resulted in this output:

/php-src/ext/gd/libgd/gd_interpolation.c:2443:17: runtime error: 7.3787e+19 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /php-src/ext/gd/libgd/gd_interpolation.c:2443:17 in

PHP Version

PHP 8.4.0-dev

Operating System

ubuntu 22.04

@cmb69
Copy link
Member

cmb69 commented Oct 9, 2024

There has been a recent change to gd_interpolation.c, so I think this now about:

bbox->width = (int) floor(max.x - min.x) - 1;

An option might be to clamp the value to fit into int, but the result should be checked. Maybe we just need to reject very large (and very small) values for the affine matrix components.

Upstream libgd might have the same issue:

https://github.com/libgd/libgd/blob/6e42ee80eb3bcf840c9fc03c6adc0550c1e02c63/src/gd_interpolation.c#L2205C2-L2205C45

Likely not relevant to this issue, but still something we may want to backport is libgd/libgd@b30fdbf; however, there was a follow up (libgd/libgd@3f50ffa) which changed that again.

@devnexen devnexen self-assigned this Oct 9, 2024
devnexen added a commit to devnexen/php-src that referenced this issue Oct 9, 2024
devnexen added a commit that referenced this issue Oct 9, 2024
@cmb69 cmb69 closed this as completed in 0511426 Oct 9, 2024
cmb69 added a commit that referenced this issue Oct 9, 2024
This reverts commit 0511426, since it
apparently has been pushed inadvertently (see PR #16334).
cmb69 added a commit that referenced this issue Oct 9, 2024
* PHP-8.2:
  Revert "Fix GH-16322: overflow on imageaffine matrix argument."
  Fix GH-16322: overflow on imageaffine matrix argument.
cmb69 added a commit that referenced this issue Oct 9, 2024
* PHP-8.3:
  Revert "Fix GH-16322: overflow on imageaffine matrix argument."
  Fix GH-16322: overflow on imageaffine matrix argument.
cmb69 added a commit that referenced this issue Oct 9, 2024
* PHP-8.4:
  Revert "Fix GH-16322: overflow on imageaffine matrix argument."
  Fix GH-16322: overflow on imageaffine matrix argument.
cmb69 added a commit that referenced this issue Oct 9, 2024
* PHP-8.2:
  Revert "Fix GH-16322: overflow on imageaffine matrix argument."
cmb69 added a commit that referenced this issue Oct 9, 2024
* PHP-8.3:
  Revert "Fix GH-16322: overflow on imageaffine matrix argument."
cmb69 added a commit that referenced this issue Oct 9, 2024
* PHP-8.4:
  Revert "Fix GH-16322: overflow on imageaffine matrix argument."
@cmb69 cmb69 reopened this Oct 10, 2024
@cmb69
Copy link
Member

cmb69 commented Oct 10, 2024

This ticket has been closed accidentially.

devnexen added a commit to devnexen/php-src that referenced this issue Oct 10, 2024
devnexen added a commit to devnexen/php-src that referenced this issue Oct 10, 2024
@cmb69 cmb69 linked a pull request Oct 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants