Mantis - Quercus
Viewing Issue Advanced Details
3134 minor always 12-07-08 00:30 12-10-08 09:15
koreth  
nam  
normal  
closed 3.2.1  
fixed  
none    
none 4.0.0  
0003134: json_decode throws exception on empty input
<?php
json_decode('', true);

Vanilla PHP executes this script; Quercus throws an exception:

[00:28:52.271] {http--8080-7} java.lang.ArrayIndexOutOfBoundsException
[00:28:52.271] {http--8080-7} at com.caucho.quercus.env.StringBuilderValue.<init>(StringBuilderValue.java:74)
[00:28:52.271] {http--8080-7} at com.caucho.quercus.env.StringBuilderValue.subSequence(StringBuilderValue.java:660)
[00:28:52.271] {http--8080-7} at com.caucho.quercus.env.StringValue.substring(StringValue.java:1671)
[00:28:52.271] {http--8080-7} at com.caucho.quercus.lib.json.JsonDecoder.errorReturn(JsonDecoder.java:409)
[00:28:52.271] {http--8080-7} at com.caucho.quercus.lib.json.JsonDecoder.errorReturn(JsonDecoder.java:392)
[00:28:52.271] {http--8080-7} at com.caucho.quercus.lib.json.JsonDecoder.jsonDecodeImpl(JsonDecoder.java:115)
[00:28:52.271] {http--8080-7} at com.caucho.quercus.lib.json.JsonDecoder.jsonDecode(JsonDecoder.java:54)
[00:28:52.271] {http--8080-7} at com.caucho.quercus.lib.json.JsonModule.json_decode(JsonModule.java:303)
[00:28:52.271] {http--8080-7} at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Notes
(0003580)
koreth   
12-07-08 09:21   
This is not a robust fix, but it lets me proceed with testing my PHP code:

--- a/modules/quercus/src/com/caucho/quercus/lib/json/JsonModule.java
+++ b/modules/quercus/src/com/caucho/quercus/lib/json/JsonModule.java
@@ -300,6 +300,8 @@ public class JsonModule
                           StringValue s,
                           @Optional("false") boolean assoc)
   {
+ if (s.length() == 0)
+ return BooleanValue.FALSE;
     return (new JsonDecoder()).jsonDecode(env, s, assoc);
   }
(0003594)
nam   
12-10-08 09:15   
php/471c