This is an automated email from the ASF dual-hosted git repository.

junichi11 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 55498fa  [NETBEANS-2881] Prevent 
java.lang.StringIndexOutOfBoundsException
     new 3858a3a  Merge pull request #1395 from 
junichi11/netbeans-2881-prevent-SIOOBE
55498fa is described below

commit 55498fa639a9b714a54efba373abeecaa0370faf
Author: Junichi Yamamoto <[email protected]>
AuthorDate: Tue Jul 23 23:53:27 2019 +0900

    [NETBEANS-2881] Prevent java.lang.StringIndexOutOfBoundsException
---
 .../javascript2/editor/parser/SanitizingParser.java        |  4 ++++
 .../modules/javascript2/editor/parser/JsonParserTest.java  | 14 ++++++++++++++
 2 files changed, 18 insertions(+)

diff --git 
a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/parser/SanitizingParser.java
 
b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/parser/SanitizingParser.java
index 686191b..26f7d6d 100644
--- 
a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/parser/SanitizingParser.java
+++ 
b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/parser/SanitizingParser.java
@@ -176,6 +176,10 @@ public abstract class SanitizingParser<R extends 
BaseParserResult> extends Parse
                 }
             } else if 
(snapshot.getMimeType().equals(JsTokenId.JSON_MIME_TYPE)) {
                 int index = text.length() - 1;
+                if (index < 0) {
+                    // NETBEANS-2881
+                    return false;
+                }
                 char ch = text.charAt(index);
                 while (index > 0 && ch != '}') {
                     index--;
diff --git 
a/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/parser/JsonParserTest.java
 
b/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/parser/JsonParserTest.java
index 8e88c55..f5f0c2a 100644
--- 
a/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/parser/JsonParserTest.java
+++ 
b/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/parser/JsonParserTest.java
@@ -147,6 +147,20 @@ public class JsonParserTest extends JsonTestBase {
         parse("{ \"a\" : [{\"w\":1}, {\"e\":2},] }", false, 
Collections.singletonList("no viable alternative at input ']'"));
     }
 
+    public void testEmpty() throws Exception {
+        try {
+            // NETBEANS-2881
+            String original = "";
+            JsonParser parser = new JsonParser(false);
+            Document doc = getDocument(original);
+            Snapshot snapshot = Source.create(doc).createSnapshot();
+            JsErrorManager manager = new JsErrorManager(snapshot, 
JsTokenId.jsonLanguage());
+            parser.parseSource(snapshot, null, JsParser.Sanitize.NEVER, 
manager);
+        } catch (StringIndexOutOfBoundsException e) {
+            fail("StringIndexOutOfBoundsException occurred: " + 
e.getMessage());
+        }
+    }
+
     private void parse(
             String original,
             boolean allowComments,


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to