From 8bd4a9fad8e687892862f422ca1252fd0831173f Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 23 Feb 2021 20:03:45 +0100 Subject: [PATCH] Fix #5999 ArrayIndexOutOfBounds for unicode in HttpURI segment (#6000) Fixed ArrayTrie to not throw if passed a unicode character. --- .../src/test/java/org/eclipse/jetty/http/HttpURITest.java | 3 +++ .../src/main/java/org/eclipse/jetty/util/ArrayTrie.java | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java index 53e385f2942..3713b5247b5 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java @@ -337,6 +337,9 @@ public class HttpURITest {"%2f/info", "//info", true}, {"%2F/info", "//info", true}, + // Non ascii characters + {"http://localhost:9000/x\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32", "/x\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32", false}, + {"http://localhost:9000/\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32", "/\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32\uD83C\uDF32", false}, }).map(Arguments::of); } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTrie.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTrie.java index b15ccef2d67..04165cf2c8a 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTrie.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTrie.java @@ -204,6 +204,8 @@ public class ArrayTrie extends AbstractTrie for (int i = 0; i < len; i++) { char c = s.charAt(offset + i); + if (c > 0x7f) + return null; int index = __lookup[c & 0x7f]; if (index >= 0) { @@ -217,7 +219,7 @@ public class ArrayTrie extends AbstractTrie char[] big = _bigIndex == null ? null : _bigIndex[t]; if (big == null) return null; - t = big[c]; + t = big[c & 0x7f]; if (t == 0) return null; }