File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
main/java/io/sentry/android/core/internal/tombstone
test/java/io/sentry/android/core/internal/tombstone Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 2020 * c0bcc3f1-9827-fe65-3058-404b2831d9e6
2121 * </pre>
2222 *
23- * Note: Java bytes are signed. When promoted (e.g. during formatting or bit shifts), they
23+ * <p> Note: Java bytes are signed. When promoted (e.g. during formatting or bit shifts), they
2424 * sign-extend to int, unlike uint8_t in C. We therefore mask with & 0xff to preserve the intended
2525 * unsigned byte values.
2626 */
@@ -78,6 +78,10 @@ private static byte[] hexToBytes(String hex) {
7878 for (int byteIdx = 0 ; byteIdx < numBytes ; byteIdx ++) {
7979 int hi = Character .digit (hex .charAt (byteIdx * 2 ), numBytes );
8080 int lo = Character .digit (hex .charAt (byteIdx * 2 + 1 ), numBytes );
81+ if (hi < 0 || lo < 0 ) {
82+ throw new IllegalArgumentException (
83+ "GUID conversion input hex string contains invalid characters" );
84+ }
8185 result [byteIdx ] = (byte ) ((hi << 4 ) | lo );
8286 }
8387 return result ;
Original file line number Diff line number Diff line change @@ -24,6 +24,19 @@ class OleGuidFormatterTest {
2424 }
2525 }
2626
27+ @Test
28+ fun `an input string with with an invalid hex character throws` () {
29+ // fail the low nibble conversion
30+ assertFailsWith<IllegalArgumentException > {
31+ OleGuidFormatter .convert(" g123456789abcdef0123456789abcdef" )
32+ }
33+
34+ // fail the high nibble conversion
35+ assertFailsWith<IllegalArgumentException > {
36+ OleGuidFormatter .convert(" 0h23456789abcdef0123456789abcdef" )
37+ }
38+ }
39+
2740 @Test
2841 fun `an input example from the develop docs leads to the expected result` () {
2942 val input = " f1c3bcc0279865fe3058404b2831d9e64135386c"
You can’t perform that action at this time.
0 commit comments