php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75139 php-7.1.9/ext/gd/libgd/gd_interpolation.c:1786: suspicious if ?
Submitted: 2017-08-31 07:20 UTC Modified: 2017-09-01 21:47 UTC
From: dcb314 at hotmail dot com Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: 7.1.9RC1 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dcb314 at hotmail dot com
New email:
PHP Version: OS:

 

 [2017-08-31 07:20 UTC] dcb314 at hotmail dot com
Description:
------------
[php-7.1.9/ext/gd/libgd/gd_interpolation.c:1786]: (style) Same expression on both sides of '&&'.

Source code is

    const gdFixed f_slop = f_slop_x > 0 && f_slop_x > 0 ?
                            f_slop_x > f_slop_y ? gd_divfx(f_slop_y, f_slop_x) : gd_divfx(f_slop_x, f_slop_y)
                        : 0;

BTW, using nested ternary operators is asking for trouble.
Suggest recode in a simpler way.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-31 14:00 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2017-08-31 22:10 UTC] cmb@php.net
-Package: Compile Warning +Package: GD related
 [2017-08-31 22:10 UTC] cmb@php.net
It seems to me that is actually a bug, because
`f_slop_x > 0 && f_slop_x > 0` appears to be supposed to be
`f_slop_x > 0 && f_slop_y > 0` to avoid a subsequent division by
zero.

Thanks for reporting this issue!

A test exhibiting the current misbehavior would be welcome.
 [2017-09-01 21:47 UTC] cmb@php.net
-Status: Assigned +Status: Analyzed
 [2017-09-01 21:47 UTC] cmb@php.net
This very issue has been fixed in external libgd with
<https://github.com/libgd/libgd/commit/dd48286>. However, it seems
to me that a division by zero cannot occur, because `f_slop_y` can
only be zero if `_angle` is 0 or π, but in the former case
`f_slop_x` would be 1, and the latter case cannot happen due to
the switch in gdImageRotateInterpolated().

Anyhow, the respective code has been removed with
<https://github.com/libgd/libgd/commit/2b26be8> to improve the
quality of the rotation result.

Neither of these, nor other, patches regarding gd_interpolation.c
has made it to our bundled libgd yet, unfortunately. I am
uncertain whether 2b26be8 could be backported without some other
patches, so I think it is best to fix the typo for PHP 7.0+, and
to try to sync the whole file for PHP 7.3+.

> BTW, using nested ternary operators is asking for trouble.
> Suggest recode in a simpler way.

As the code is likely to vanish, putting the inner ternary
operation in parentheses appears to be sufficient.
 [2017-09-01 22:29 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e20a6b0213e108da50293d1fff885f507e6115ac
Log: Fixed bug #75139 (libgd/gd_interpolation.c:1786: suspicious if ?)
 [2017-09-01 22:29 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 27 16:01:27 2024 UTC