From 5d7b722f6e20232a5e03d76f10c5c9554ab754a9 Mon Sep 17 00:00:00 2001 From: Robin Stocker Date: Tue, 19 Feb 2013 23:41:15 +0100 Subject: [PATCH] Fix false positives in hashing used by PathFilterGroup The ByteArraySet failed to check the length of the entry correctly leading to matches where no match should be. Bug: 401249 Change-Id: I925bc48d9cafcdf13e1a797bb09fc2555eb270c5 Signed-off-by: Robin Rosenberg --- .../jgit/treewalk/filter/PathFilterGroupTest.java | 13 +++++++++++++ .../eclipse/jgit/treewalk/filter/ByteArraySet.java | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java index 5267e81a1..8038206e9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java @@ -134,6 +134,19 @@ public void testFilterIsPrefixOfKey() throws MissingObjectException, assertTrue(filter.include(fakeWalk("d/e/f/g/h"))); } + @Test + public void testLongPaths() throws MissingObjectException, + IncorrectObjectTypeException, IOException { + TreeFilter longPathFilter = PathFilterGroup + .createFromStrings( + "tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java", + "tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest2.java"); + assertFalse(longPathFilter + .include(fakeWalk("tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java"))); + assertFalse(longPathFilter.include(fakeWalk("tst/a-other-in-same"))); + assertFalse(longPathFilter.include(fakeWalk("a-nothing-in-common"))); + } + @Test public void testStopWalk() throws MissingObjectException, IncorrectObjectTypeException, IOException { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java index 0df24af24..5a3535982 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java @@ -88,7 +88,7 @@ private byte[] get(final byte[] toFind, int length, int hash) { } private static boolean equals(byte[] a, byte[] b, int length) { - if (a.length < length || b.length < length) + if (a.length != length || b.length < length) return false; for (int i = 0; i < length; ++i) { if (a[i] != b[i])