PHP_INT_MAX as Array Key causes an Exception
Posted: November 1st, 2013, 5:11 pm
Hello,
I found a glitch when using Array with a maximum int key. If I try to use PHP_INT_MAX as key value, it produces an "Arithmetic operation resulted in an overflow" exception.
Simple test case:
That code will produce this exception:
If I change the index to:
It will work.
For code that I own, it is easy to fix, but for 3rd party libs or plugins it will case headaches!
Any ideas how to fix that?...
Thank you.
I found a glitch when using Array with a maximum int key. If I try to use PHP_INT_MAX as key value, it produces an "Arithmetic operation resulted in an overflow" exception.
Simple test case:
- Code: Select all
var_dump(PHP_INT_MAX);
$xxx[PHP_INT_MAX] = 'XXX';
var_dump($xxx);
That code will produce this exception:
- Code: Select all
Arithmetic operation resulted in an overflow.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.OverflowException: Arithmetic operation resulted in an overflow.
Source Error:
Line 17: var_dump(PHP_INT_MAX);
Line 18:
Line 19: $xxx[PHP_INT_MAX] = 'XXX';
Line 20:
Line 21: var_dump($xxx);
Source File: C:\inetpub\deleteme01\sample.php Line: 19
Stack Trace:
[OverflowException: Arithmetic operation resulted in an overflow.]
PHP.Core.PhpHashtable.KeyAdded(Int32 key) +106
PHP.Core.PhpHashtable.KeyAdded(IntStringKey& key) +111
PHP.Core.OrderedDictionary._add_or_update_preserve_ref(PhpArray array, IntStringKey& key, Object value) +790
PHP.Core.PhpArray.SetArrayItem(IntStringKey key, Object value) +139
PHP.Core.PhpArray.SetArrayItem(Object key, Object value) +233
PHP.Core.Operators.SetItemEpilogue(Object value, Object key, Object& var) +151
PHP.Core.Operators.SetItemEpilogue(Object value, Int32 key, Object& var) +1237
PHP.Core.Operators.SetItem(Object value, Int32 key, Object& var) +356
<sample.php>.<Script>.<Main>(ScriptContext <context>, Dictionary`2 <locals>, DObject <self>, DTypeDesc <includer>, Boolean <request>) in C:\inetpub\deleteme01\sample.php:19
PHP.Core.ScriptInfo.<get_Main>b__0(ScriptContext context, Dictionary`2 variables, DObject self, DTypeDesc includer, Boolean isMain) +102
PHP.Core.ScriptContext.<IncludeScript>b__1(ScriptInfo scriptInfo) +75
PHP.Core.ScriptContext.GuardedCall(Converter`2 routine, TData data, Boolean allowUserExceptions) +336
[PhpNetInternalException: Guarded call
InnerException: Arithmetic operation resulted in an overflow.
at at PHP.Core.PhpHashtable.KeyAdded(Int32 key)
at PHP.Core.PhpHashtable.KeyAdded(IntStringKey& key)
at PHP.Core.OrderedDictionary._add_or_update_preserve_ref(PhpArray array, IntStringKey& key, Object value)
at PHP.Core.PhpArray.SetArrayItem(IntStringKey key, Object value)
at PHP.Core.PhpArray.SetArrayItem(Object key, Object value)
at PHP.Core.Operators.SetItemEpilogue(Object value, Object key, Object& var)
at PHP.Core.Operators.SetItemEpilogue(Object value, Int32 key, Object& var)
at PHP.Core.Operators.SetItem(Object value, Int32 key, Object& var)
at <sample.php>.<Script>.<Main>(ScriptContext <context>, Dictionary`2 <locals>, DObject <self>, DTypeDesc <includer>, Boolean <request>) in C:\inetpub\deleteme01\sample.php:line 19
at PHP.Core.ScriptInfo.<get_Main>b__0(ScriptContext context, Dictionary`2 variables, DObject self, DTypeDesc includer, Boolean isMain)
at PHP.Core.ScriptContext.<IncludeScript>b__1(ScriptInfo scriptInfo)
at PHP.Core.ScriptContext.GuardedCall[TData,TResult](Converter`2 routine, TData data, Boolean allowUserExceptions)
]
PHP.Core.ScriptContext.GuardedCall(Converter`2 routine, TData data, Boolean allowUserExceptions) +595
PHP.Core.ScriptContext.IncludeScript(String relativeSourcePath, ScriptInfo script) +437
PHP.Core.RequestContext.IncludeScript(String relativeSourcePath, ScriptInfo script) +157
PHP.Core.RequestHandler.ProcessRequest(HttpContext context) +438
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
If I change the index to:
- Code: Select all
var_dump(PHP_INT_MAX);
$xxx[PHP_INT_MAX - 1] = 'XXX';
var_dump($xxx);
It will work.
For code that I own, it is easy to fix, but for 3rd party libs or plugins it will case headaches!
Any ideas how to fix that?...
Thank you.