From d7f304045af2f602c5b0c1a26d2c7f643753cf8f Mon Sep 17 00:00:00 2001 From: Michael Dardis Date: Wed, 4 Mar 2020 15:25:09 +1100 Subject: Add validation to hex decoder Does not fix any issue but prevents user from shooting themselves in the foot with improper configuration. Suggested by Demetr Starshov at https://git.eclipse.org/r/#/c/157681/ Change-Id: I006d65022f0a7d4066970825d00080c59404fdc3 Signed-off-by: Michael Dardis Signed-off-by: Matthias Sohn --- .../tst/org/eclipse/jgit/util/HexTest.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'org.eclipse.jgit.test/tst/org') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HexTest.java index 32af07f259..5f3ab0b775 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HexTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HexTest.java @@ -42,6 +42,31 @@ public class HexTest { } } + @Test(expected = IllegalArgumentException.class) + public void testIllegal() { + decode("0011test00"); + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegal2() { + decode("0123456789abcdefgh"); + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegal3() { + decode("0123456789abcdef-_+*"); + } + + @Test + public void testLegal() { + decode("0123456789abcdef"); + } + + @Test + public void testLegal2() { + decode("deadbeef"); + } + private static byte[] b(String str) { return Constants.encode(str); } -- cgit v1.2.3