[jruby-joni] 56/223: Fix for JRUBY-4382. The fix is to ensure that a region never walks off the end of the buffer by adding a range check in opCClassNot and opCClass, similar to MRI's regex.c line 3914 on branch ruby_1_8_7 at 26113.
Hideki Yamane
henrich at moszumanska.debian.org
Mon Nov 16 11:21:47 UTC 2015
This is an automated email from the git hooks/post-receive script.
henrich pushed a commit to branch debian/sid
in repository jruby-joni.
commit aec57665bf88769ddf84113aadf7a1e546e6a0ed
Author: Charles Oliver Nutter <headius at headius.com>
Date: Wed Dec 23 16:28:23 2009 -0600
Fix for JRUBY-4382. The fix is to ensure that a region never walks off the end of the buffer by adding a range check in opCClassNot and opCClass, similar to MRI's regex.c line 3914 on branch ruby_1_8_7 at 26113.
---
src/org/joni/ByteCodeMachine.java | 2 ++
test/org/joni/test/TestJoni.java | 3 ++
test/org/joni/test/TestNSU8.java | 65 +++++++++++++++++++++++++++++++++++++++
3 files changed, 70 insertions(+)
diff --git a/src/org/joni/ByteCodeMachine.java b/src/org/joni/ByteCodeMachine.java
index bcaea73..9ca1988 100644
--- a/src/org/joni/ByteCodeMachine.java
+++ b/src/org/joni/ByteCodeMachine.java
@@ -623,6 +623,7 @@ class ByteCodeMachine extends StackMachine {
if (s >= range || !isInBitSet()) {opFail(); return;}
ip += BitSet.BITSET_SIZE;
s += enc.length(bytes, s, end); /* OP_CCLASS can match mb-code. \D, \S */
+ if (s > end) s = end;
sprev = sbegin; // break;
}
@@ -672,6 +673,7 @@ class ByteCodeMachine extends StackMachine {
if (s >= range || isInBitSet()) {opFail(); return;}
ip += BitSet.BITSET_SIZE;
s += enc.length(bytes, s, end);
+ if (s > end) s = end;
sprev = sbegin; // break;
}
diff --git a/test/org/joni/test/TestJoni.java b/test/org/joni/test/TestJoni.java
index 6fb14cc..f1cb9ec 100644
--- a/test/org/joni/test/TestJoni.java
+++ b/test/org/joni/test/TestJoni.java
@@ -7,11 +7,13 @@ public class TestJoni extends TestCase {
private Test testa;
private Test testc;
private Test testu;
+ private Test testnsu8;
protected void setUp() {
testa = new TestA();
testc = new TestC();
testu = new TestU();
+ testnsu8 = new TestNSU8();
}
protected void tearDown() {
@@ -33,5 +35,6 @@ public class TestJoni extends TestCase {
public void testUnicode() {
testJoniTest(testu);
+ testJoniTest(testnsu8);
}
}
diff --git a/test/org/joni/test/TestNSU8.java b/test/org/joni/test/TestNSU8.java
new file mode 100644
index 0000000..54dd902
--- /dev/null
+++ b/test/org/joni/test/TestNSU8.java
@@ -0,0 +1,65 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package org.joni.test;
+
+import org.joni.Option;
+import org.joni.Syntax;
+import org.jcodings.Encoding;
+import org.jcodings.specific.NonStrictUTF8Encoding;
+
+public class TestNSU8 extends Test {
+
+ public int option() {
+ return Option.DEFAULT;
+ }
+
+ public Encoding encoding() {
+ return NonStrictUTF8Encoding.INSTANCE;
+ }
+
+ public String testEncoding() {
+ return "utf-8";
+ }
+
+ public Syntax syntax() {
+ return Syntax.DEFAULT;
+ }
+
+ public void test() {
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)240, (byte)32, (byte)32, (byte)32, (byte)32}, 0, 5, 1, false);
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)240, (byte)32, (byte)32, (byte)32}, 0, 4, 1, false);
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)240, (byte)32, (byte)32}, 0, 3, 1, false);
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)240, (byte)32}, 0, 2, 1, false);
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)240}, 0, 1, 1, false);
+
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)224, (byte)32, (byte)32, (byte)32}, 0, 4, 1, false);
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)224, (byte)32, (byte)32}, 0, 3, 1, false);
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)224, (byte)32}, 0, 2, 1, false);
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)224}, 0, 1, 1, false);
+
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)192, (byte)32, (byte)32}, 0, 3, 1, false);
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)192, (byte)32}, 0, 2, 1, false);
+ xx("([^\\[\\]]+)".getBytes(), new byte[]{(byte)192}, 0, 1, 1, false);
+ }
+
+ public static void main(String[] args) throws Throwable {
+ new TestNSU8().run();
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git
More information about the pkg-java-commits
mailing list