Repository: tomee Updated Branches: refs/heads/master d8af78498 -> a0bb33e78
TOMEE-1970 avoid infinite loops for json files without a closing quote for strings Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a0bb33e7 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a0bb33e7 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a0bb33e7 Branch: refs/heads/master Commit: a0bb33e7833f60e9416098fd2c519025d42b53db Parents: d8af784 Author: rmannibucau <rmannibu...@apache.org> Authored: Tue Nov 15 08:50:05 2016 +0100 Committer: rmannibucau <rmannibu...@apache.org> Committed: Tue Nov 15 08:50:05 2016 +0100 ---------------------------------------------------------------------- .../apache/openejb/util/SimpleJSonParser.java | 8 ++-- .../openejb/util/SimpleJSonParserTest.java | 42 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/a0bb33e7/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java b/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java index e53e612..99ea6a7 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java @@ -50,9 +50,9 @@ public final class SimpleJSonParser { current = (char) read; b.append(current); - } while (current != -1 && current != '\"'); + } while (read != -1 && current != '\"'); - if (current == -1) { + if (read == -1) { throw new IllegalArgumentException("String should be between \""); } @@ -67,7 +67,7 @@ public final class SimpleJSonParser { current = (char) read; b.append(current); - } while (current != -1 && !isWhiteSpace(current) && current != ','); + } while (read != -1 && !isWhiteSpace(current) && current != ','); final String value = PropertyPlaceHolderHelper.simpleValue(b.substring(0, b.length() - 1)); // remove last character if (valueRead(is, json, array, value)) { @@ -86,7 +86,7 @@ public final class SimpleJSonParser { do { read = is.read(); c = (char) read; - } while (c != -1 && c != ':' && c != '=' && (c == ',' || c == '\n' || c == '\r')); + } while (read != -1 && c != ':' && c != '=' && (c == ',' || c == '\n' || c == '\r')); if (json != null) { json.put(value, read(is)); http://git-wip-us.apache.org/repos/asf/tomee/blob/a0bb33e7/container/openejb-core/src/test/java/org/apache/openejb/util/SimpleJSonParserTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/util/SimpleJSonParserTest.java b/container/openejb-core/src/test/java/org/apache/openejb/util/SimpleJSonParserTest.java new file mode 100644 index 0000000..dddaa91 --- /dev/null +++ b/container/openejb-core/src/test/java/org/apache/openejb/util/SimpleJSonParserTest.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.util; + +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import static org.junit.Assert.assertNotNull; + +public class SimpleJSonParserTest { + @Test + public void avoidInfiniteLoop_TOMEE1970() throws IOException { // was throwing java.lang.OutOfMemoryError: Java heap space + assertNotNull(SimpleJSonParser.read(new ByteArrayInputStream(("{\n" + + " \"resources\":{\n" + + " \"jdbc/test\":{\n" + + " \"type\":\"DataSource\",\n" + + " \"classpath\":\"whatever\",\n" + + " \"properties\":{\n" + + " \"a\":\"b\n" + // no closing quote is the TOMEE61970 issue + " }\n" + + " }\n" + + " }\n" + + "}\n").getBytes(StandardCharsets.UTF_8)))); + } +}