You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-dev@hadoop.apache.org by "Marcono1234 (Jira)" <ji...@apache.org> on 2021/03/27 17:45:00 UTC
[jira] [Created] (MAPREDUCE-7333) SecureShuffleUtils.toHex(byte[])
creates malformed hex string
Marcono1234 created MAPREDUCE-7333:
--------------------------------------
Summary: SecureShuffleUtils.toHex(byte[]) creates malformed hex string
Key: MAPREDUCE-7333
URL: https://issues.apache.org/jira/browse/MAPREDUCE-7333
Project: Hadoop Map/Reduce
Issue Type: Bug
Affects Versions: 3.2.2
Reporter: Marcono1234
{{org.apache.hadoop.mapreduce.security.SecureShuffleUtils.toHex(byte[])}} creates malformed hex strings:
{code}
for (byte b : ba) {
ps.printf("%x", b);
}
{code}
The pattern {{"%x"}} would for bytes < 16 only have on hex char and for example both {{1, 0}} and {{16}} would have the result {{"10"}}.
A correct (and more efficient) implementation would be:
{code}
public static String toHex(byte[] ba) {
StringBuilder sb = new StringBuilder(ba.length * 2);
for (byte b : ba) {
int unsignedB = b & 0xFF;
if (unsignedB < 16) {
sb.append('0');
}
sb.append(Integer.toHexString(unsignedB));
}
return sb.toString();
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: mapreduce-dev-unsubscribe@hadoop.apache.org
For additional commands, e-mail: mapreduce-dev-help@hadoop.apache.org