You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/06/27 04:42:04 UTC
(groovy) branch master updated (5450aed5ab -> 1f91df683e)
This is an automated email from the ASF dual-hosted git repository.
paulk-asert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
from 5450aed5ab minor refactor: fix merge glitch
new 0574e5b543 GROOVY-12107: reject non-hex characters in decodeHex
new 1f91df683e GROOVY-12107: reject non-hex characters in decodeHex (cont'd)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/codehaus/groovy/runtime/EncodingGroovyMethods.java | 9 ++++++++-
src/test/groovy/groovy/HexTest.groovy | 13 +++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
(groovy) 02/02: GROOVY-12107: reject non-hex characters in decodeHex (cont'd)
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk-asert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 1f91df683e6dbf1f235a6a19f77d28434d550fdd
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Jun 27 14:41:53 2026 +1000
GROOVY-12107: reject non-hex characters in decodeHex (cont'd)
---
src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
index b49f180fb9..a5edb1f75b 100644
--- a/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
@@ -382,7 +382,7 @@ public class EncodingGroovyMethods {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
- throw new NumberFormatException("illegal hexadecimal character " + c + " in hex string");
+ throw new NumberFormatException("illegal hexadecimal character '" + c + "' in hex string");
}
/**
(groovy) 01/02: GROOVY-12107: reject non-hex characters in decodeHex
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk-asert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 0574e5b5438c8b434218526803232bd62e84ad6d
Author: Kartik Kenchi <ne...@gmail.com>
AuthorDate: Fri Jun 26 01:55:50 2026 +0530
GROOVY-12107: reject non-hex characters in decodeHex
---
.../org/codehaus/groovy/runtime/EncodingGroovyMethods.java | 9 ++++++++-
src/test/groovy/groovy/HexTest.groovy | 13 +++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
index 816df786b3..b49f180fb9 100644
--- a/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
@@ -372,12 +372,19 @@ public class EncodingGroovyMethods {
byte[] bytes = new byte[value.length() / 2];
for (int i = 0; i < value.length(); i += 2) {
- bytes[i / 2] = (byte) Integer.parseInt(value.substring(i, i + 2), 16);
+ bytes[i / 2] = (byte) ((hexToNibble(value.charAt(i)) << 4) | hexToNibble(value.charAt(i + 1)));
}
return bytes;
}
+ private static int hexToNibble(final char c) {
+ if (c >= '0' && c <= '9') return c - '0';
+ if (c >= 'A' && c <= 'F') return c - 'A' + 10;
+ if (c >= 'a' && c <= 'f') return c - 'a' + 10;
+ throw new NumberFormatException("illegal hexadecimal character " + c + " in hex string");
+ }
+
/**
* Calculate md5 of the CharSequence instance
* @return md5 value
diff --git a/src/test/groovy/groovy/HexTest.groovy b/src/test/groovy/groovy/HexTest.groovy
index 2e90fe88fe..a881440158 100644
--- a/src/test/groovy/groovy/HexTest.groovy
+++ b/src/test/groovy/groovy/HexTest.groovy
@@ -67,6 +67,19 @@ class HexTest {
"1g".decodeHex()
}
+ // a leading sign is not a valid hexadecimal character and must be rejected
+ // (Integer.parseInt would otherwise accept it and decode a wrong byte)
+ ["-1", "+a", "-f", "+0"].each { bad ->
+ shouldFail(NumberFormatException) {
+ bad.decodeHex()
+ }
+ }
+
+ // non-ASCII digit characters are not valid hexadecimal either
+ shouldFail(NumberFormatException) {
+ "11".decodeHex()
+ }
+
// test to make sure a leading zero is handled correctly
bytes = "0a".decodeHex()
assert bytes.length == 1