From 9b8d0db61337ecc23ded48829dbd603771214db8 Mon Sep 17 00:00:00 2001 From: gregw Date: Tue, 23 Feb 2021 16:52:21 +0100 Subject: [PATCH] Fix #5999 ArrayIndexOutOfBounds for unicode in HttpURI segment 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 53e385f2942c..3713b5247b5d 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 static Stream decodePathTests() {"%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 b15ccef2d67c..04165cf2c8ad 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 V get(String s, int offset, int len) 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 V get(String s, int offset, int len) char[] big = _bigIndex == null ? null : _bigIndex[t]; if (big == null) return null; - t = big[c]; + t = big[c & 0x7f]; if (t == 0) return null; }