提交 9456a024 编写于 作者: A alanb

6925932: (file) Path.endsWith can throw ArrayIndexOutOfBoundsException (unx)

Reviewed-by: chegar
上级 f7799fb3
......@@ -624,8 +624,11 @@ class UnixPath
public boolean endsWith(Path other) {
UnixPath that = checkPath(other);
int thisLen = path.length;
int thatLen = that.path.length;
// other path is longer
if (that.path.length > path.length)
if (thatLen > thisLen)
return false;
// other path is absolute so this path must be absolute
......@@ -643,10 +646,10 @@ class UnixPath
if (thatOffsetCount == thisOffsetCount) {
if (thisOffsetCount == 0)
return true;
int expectedLen = path.length;
int expectedLen = thisLen;
if (this.isAbsolute() && !that.isAbsolute())
expectedLen--;
if (that.path.length != expectedLen)
if (thatLen != expectedLen)
return false;
} else {
// this path has more elements so given path must be relative
......@@ -658,7 +661,9 @@ class UnixPath
// compare bytes
int thisPos = offsets[thisOffsetCount - thatOffsetCount];
int thatPos = that.offsets[0];
while (thatPos < that.path.length) {
if ((thatLen - thatPos) != (thisLen - thisPos))
return false;
while (thatPos < thatLen) {
if (this.path[thisPos++] != that.path[thatPos++])
return false;
}
......
......@@ -22,7 +22,7 @@
*/
/* @test
* @bug 4313887 6838333
* @bug 4313887 6838333 6925932
* @summary Unit test for java.nio.file.Path path operations
*/
......@@ -614,17 +614,34 @@ public class PathOps {
test("/foo")
.ends("foo")
.ends("/foo")
.notEnds("/");
.notEnds("fool");
test("/foo/bar")
.ends("bar")
.ends("foo/bar")
.ends("/foo/bar")
.notEnds("/bar");
.notEnds("ar")
.notEnds("barack")
.notEnds("/bar")
.notEnds("o/bar");
test("foo")
.ends("foo");
.ends("foo")
.notEnds("oo")
.notEnds("oola");
test("foo/bar")
.ends("bar")
.ends("foo/bar");
.ends("foo/bar")
.notEnds("r")
.notEnds("barmaid")
.notEnds("/bar");
test("foo/bar/gus")
.ends("gus")
.ends("bar/gus")
.ends("foo/bar/gus")
.notEnds("g")
.notEnds("/gus")
.notEnds("r/gus")
.notEnds("barack/gus")
.notEnds("bar/gust");
// elements
test("a/b/c")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册