#48093 [Bgs]: Generated index is reset due to integer overflow

2009-06-07 Thread mattwil
 ID:   48093
 Updated by:   matt...@php.net
 Reported By:  Marcel dot Glacki at stud dot fh-swf dot de
 Status:   Bogus
 Bug Type: Arrays related
 Operating System: *
 PHP Version:  5.2.9
 New Comment:

Your initial report is technically correct, as far as what's happening
internally, and the second example shows it -- the initial example would
too if this line is commented/removed:

$arr[1] = 'one'; // New index: 2

Otherwise, this is a duplicate of Bug #47836, which is now fixed. The
initial code will still give the same warning (I'm sure you expect that
though), but for a different reason internally. :-)


Previous Comments:


[2009-04-28 14:03:13] Marcel dot Glacki at stud dot fh-swf dot de

Hi,

well, I checked the manual (even in other languages). But if I missed
something essential let me know.

What I wanted to point out is, that the manual says integers are
converted to float if an integer overflow is encountered. (See:
http://www.php.net/manual/en/language.types.integer.php at section
"Integer overflow")

Furthermore the manual says about using arrays if when no index is
given the array generates itself an index to use. (See:
http://www.php.net/manual/en/language.types.array.php at section
"Creating/modifying with square bracket syntax") It says: "As mentioned
above, if no key is specified, the maximum of the existing integer
indices is taken, and the new key will be that maximum value plus 1."

So what happens when this maximum value is already MAX_INT ? It then is
not converted to float and if so, it would then be truncated to integer
... and then the integer overflow comes across.

Again, the manual says "the MAXIMUM of the existing integer indices ...
is taken" and that's just not true for the code I provided in the first
post and the one down below.

Here's another code sample to show:



Which prints:
Array
(
[0] => some
[2147483647] => values
[-2147483648] => another
[-2147483647] => value
)


Regards,
Marcel



[2009-04-28 07:55:29] sni...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php





[2009-04-27 23:02:39] Marcel dot Glacki at stud dot fh-swf dot de

Description:

The generated index normally has the highest integer value regarding
all integers it has encountered as indexes before. (And is automatically
increased by +1)

It is possible to reset this index (the internal pointer) not only by
the functions intended to do so (like reset()) but also by increasing it
above integers' max value (integer overflow).

Reproduce code:
---







-- 
Edit this bug report at http://bugs.php.net/?id=48093&edit=1



#48093 [Bgs]: Generated index is reset due to integer overflow

2009-04-28 Thread Marcel dot Glacki at stud dot fh-swf dot de
 ID:   48093
 User updated by:  Marcel dot Glacki at stud dot fh-swf dot de
 Reported By:  Marcel dot Glacki at stud dot fh-swf dot de
 Status:   Bogus
 Bug Type: Arrays related
 Operating System: *
 PHP Version:  5.2.9
 New Comment:

Hi,

well, I checked the manual (even in other languages). But if I missed
something essential let me know.

What I wanted to point out is, that the manual says integers are
converted to float if an integer overflow is encountered. (See:
http://www.php.net/manual/en/language.types.integer.php at section
"Integer overflow")

Furthermore the manual says about using arrays if when no index is
given the array generates itself an index to use. (See:
http://www.php.net/manual/en/language.types.array.php at section
"Creating/modifying with square bracket syntax") It says: "As mentioned
above, if no key is specified, the maximum of the existing integer
indices is taken, and the new key will be that maximum value plus 1."

So what happens when this maximum value is already MAX_INT ? It then is
not converted to float and if so, it would then be truncated to integer
... and then the integer overflow comes across.

Again, the manual says "the MAXIMUM of the existing integer indices ...
is taken" and that's just not true for the code I provided in the first
post and the one down below.

Here's another code sample to show:



Which prints:
Array
(
[0] => some
[2147483647] => values
[-2147483648] => another
[-2147483647] => value
)


Regards,
Marcel


Previous Comments:


[2009-04-28 07:55:29] sni...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php





[2009-04-27 23:02:39] Marcel dot Glacki at stud dot fh-swf dot de

Description:

The generated index normally has the highest integer value regarding
all integers it has encountered as indexes before. (And is automatically
increased by +1)

It is possible to reset this index (the internal pointer) not only by
the functions intended to do so (like reset()) but also by increasing it
above integers' max value (integer overflow).

Reproduce code:
---







-- 
Edit this bug report at http://bugs.php.net/?id=48093&edit=1