php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49207 Integer Wrap stopped working properly
Submitted: 2009-08-10 10:13 UTC Modified: 2009-08-13 13:57 UTC
From: ronlentjes at yahoo dot com dot au Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.0 OS: Linux Fedora 8
Private report: No CVE-ID: None
 [2009-08-10 10:13 UTC] ronlentjes at yahoo dot com dot au
Description:
------------
Old version are correct.
Eg 4.2.2 is exhibiting correct integer behavior.
Wrapping issue. All tests on 40 other languages pass according to this simple test:

Ver 4.2.2

$n = 2147483647;
$n = (int) ($n + 1)
 -> -2147483648 (+wrap, correct)
$n = (int) ($n - 1)
 -> 2147483647 (-wrap, correct)

(C/C++/C#/.../assembly inc,dec/perl(int mode)/python/so on follow
this logic)

Ver 5.2.4

$n = 2147483647;
$n = (int) ($n + 1)
 -> -2147483648 (+wrap, correct)
$n = (int) ($n - 1)
 -> -2147483648 (-max, wrong)

(no other language follow this. Some languages do use +/-max but not
this mix of wrap one way and max the other)

Suggest: back to original +/- wrapping.

Your newer versions are wrong.
You wrap going positive around the integer wheel.
You don't wrap going negative around the integer wheel.
One direction you wrap, the other direction you do a max.

I test all languages and this is incorrect integer behavior.
Your original logic was correct but now broken and affects all
original source code.

Related issue by someone else: 
#30315. Got closed but core issue misunderstood.

Cheers, Ron Lentjes, LC CLS.


Reproduce code:
---------------
Sorry, didn't see these boxes. See above.

Your version is irrelavent here as I am talking about a change from old to new versionS. New ones don't work. (I could not select irrelavent so just chose one on list - but that's not the point).


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-10 10:35 UTC] jani@php.net
Exactly what version produces correct result (in your opinion) and _exactly_ what version does not?
 [2009-08-10 11:37 UTC] scottmac@php.net
Works for me in 5.3.0

<?php
$n = 2147483647;
$n = (int) ($n + 1);
var_dump($n);
$n = (int) ($n - 1);
var_dump($n);
?>

Produces
int(-2147483648)
int(2147483647)
 [2009-08-10 23:20 UTC] ronlentjes at yahoo dot com dot au
Ok, I tried that exact code even though results must be same.
That worked on 4.2.2.
That did not work on 5.2.4.
I will download the latest I can find for Fedora 8.
If I can't test 5.3.0, I will get latest Fedora and try again.
Get back to you as soon as I can.

I couldn't find that apparent fix on you lists? Do you know of a fix that you made? One difference I noted between those 2 versions is that printf() rounds differently. It now rounds with half-even logic instead of half-up rounding. Also, it is more in-line with all other languages now in that your old %5.2f use to mean 5 before, 2 after instead of the expected (and your now current impl of) 5 is width, with 2 decimal places after decimal. This good guys, but I couldn't find a note about this fix. Fortunately my tests picked this up right away.

half-up:   1<-->-->2<-->-->3  (1.5, 2.5 -> always up to 2 and 3)
half-even: 1<-->-->2<--<-->3  (1.5, 2.5 -> even of 2 and 3 -> 2 for both)

C/C++ on linux uses half-even so you are in-line with C/C++ now. You must have had some custom printf() thing before.

My point is that you made several changes to some major module? Or is this related in someway to a new GCC?

Ok, I'll upgrade in steps (first to php5 latest for Fed 8) and then make another HD with latest Fedora just to confirm what fixes the issue.

Cheers, Ron Lentjes, LC CLS.
 [2009-08-11 09:42 UTC] jani@php.net
Please don't report bugs in ancient versions. We only support the latest releases.
 [2009-08-13 08:39 UTC] ronlentjes at yahoo dot com dot au
Hi, I've been trying all day to install 5.3.0 on Fedora 8. Apache starts up no problem (as it did for 5.2.4). Config looks ok. But output is mostly blank pages and sometimes shows correct results. But reload and blank page again. This server still works for all other languages. I was trying to confirm issue here with latest version but can't get latest version to work. 5.2.4 worked just before rpm -ev and then rpm -ivh 5.3.0 rpms. I installed:
php-common-5.3.0-1.fc8.remi.i386.rpm
php-cli-5.3.0-1.fc8.remi.i386.rpm
php-5.3.0-1.fc8.remi.i386.rpm
php-devel-5.3.0-1.fc8.remi.i386.rpm
Resulted in Apache starting without error but complaining about <? when blank page occurs. But will produce output randomly (even exactly correct output). Simple test of hello does not work.
Other users on internet complain similarly to blank page problem for 5.3.0.

Here is the simplist I could attach as example:
----
<? error_reporting (E_ALL); ?>
<html><head></head><body>

<?= "hi<br>" ?>

</body></html>
----
Either blank page or 
" ?>
is output.

At first, I thought it was just not mapping .php but the config file seems ok and syntax chk and module php5_module shows up in apache chk.
/etc/httpd/conf.d was updated with php.conf and so on. 

Puzzled, since 5.2.4 worked a charm just before this install.

Cheers,
Ron Lentjes
LC CLS.
 [2009-08-13 10:06 UTC] ronlentjes at yahoo dot com dot au
Ok, still working on this.
I purposely changed php.ini to force error.
Apache definitely reading it.
I also made not accept file type and shows raw PHP code as text on browser then put back as should be and just get blank page or pieces of text.

Then, I tried to run the simplist thing with php command line:

---
<html><head></head><body>

<?= "hi<br>" ?>

</body></html>
---

On box with 5.2.4, get this (it works):

# php hi.php
---
<html><head></head><body>

hi<br>
</body></html>
---

On box with 5.3.0 (removed 5.2.4, installed 5.3.0), get this (it does not work!):

# php hi.php
---
<html><head></head><body>

<?= "hi<br>" ?>

</body></html>
---

BTW, It never did work (when I said sometimes correctly shown - I accidentally hit the swtich on the working computer and saw it on the working computer).

Ok, now I will concentrate on just the php command line see why it not  working with expression  <?= ... ?> ??? is that still valid PHP code or did that change in 5.3.0??

Cheers,
Ron Lentjes
LC CLS.
 [2009-08-13 13:57 UTC] ronlentjes at yahoo dot com dot au
Ok, I aborted trying to use <?= expression ?>. Then I look through your latest documentation. No mention at all about this change. Finally I found something in the php.ini file:

short_open_tag = Off

Turned that On and all the tests started working and blank pages were gone!

Then I looked into you latest 5.3.0 docs again. It says:

List of php.ini directives
[name]            [default]
short_open_tag "1" 

But that's now what got installed. It's default is now Off.

This explains a whole bunch of confused users out there wondering why they get blank screens!!! 

I would like to very much point out that as you upgrade, it would be in the very best interest of your users not to get surprised like this. Please try to keep things backward compatible. I waisted a whole  day on this and time is $MONEY$. Please DO NOT DEPRECATE old syntax. Keep moving ahead. Nothing more kills a project than not keeping backward compatibility.

Your printf() changing with %<before>.<after>f to %<width>.<after> and no where documenting this has cause trouble for many users. I have to change EVERY LINE of printf's like that and keep SEPARATE versions for older host sites that have not upgraded. A real nightmare.

Finally tested your integer wrapping and yes, it does work with 5.3.0. 
as you indicated.

You may now close this issue.

I will report a few more bugs that still exist in 5.3.0 as separate issues.

Cheers,
Ron Lentjes
LC CLS.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 09:01:28 2024 UTC