utils: enforce MoneroError contract in validateAddress
What changed, and why it matters
This commit fixes a bug in a Monero Java library where checking whether an address is valid could accidentally throw a raw, confusing error (such as 'Overflow 2') instead of cleanly returning false. The change makes sure malformed addresses are wrapped in the library's standard MoneroError so callers get predictable behavior.
Review other validation helpers in MoneroUtils for similar unchecked exception leaks, ensure all decode/parse failures are normalized to MoneroError, and consider adding fuzz-style malformed address tests.
Security signals we found
Unchecked exception leak from address validation
API contract violation in input validation routine
Potential denial-of-service vector if callers do not handle raw RuntimeException from validation
Missing test coverage for malformed address formats
Evidence from the diff
In MoneroUtils.validateAddress(), malformed addresses were reaching decodeAddress() and throwing unchecked RuntimeExceptions (e.g., an ‘Overflow 2’ from base58 decoding) that leaked through as raw exceptions rather than being converted to MoneroError. The patch catches MoneroError explicitly and rethrows it, then catches AssertionError or RuntimeException and wraps it in MoneroError, restoring the documented contract that invalid input produces a MoneroError. A new test case with a malformed mainnet address is added.
Changed components
src/main/java/monero/common/MoneroUtils.javasrc/test/java/TestMoneroUtils.javaInspect captured patch +4 / −1
### src/main/java/monero/common/MoneroUtils.java
@@ -399,7 +399,9 @@ public static void validateAddress(String address, MoneroNetworkType networkType
try {
MoneroDecodedAddress decodedAddress = decodeAddress(address);
GenUtils.assertEquals("Address network type mismatch: " + networkType + " vs " + decodedAddress.getNetworkType(), networkType, decodedAddress.getNetworkType());
- } catch (AssertionError e) {
+ } catch (MoneroError e) {
+ throw e;
+ } catch (AssertionError | RuntimeException e) {
throw new MoneroError(e.getMessage());
}
}
### src/test/java/TestMoneroUtils.java
@@ -177,6 +177,7 @@ public void testAddressValidation() {
testInvalidAddress("42ZxX3Y2y5s4nJ8fdz2w65TrTEp9PRsv5J8iHSShkHQcE2V31FhnWptioNst1K9oeDY4KpWZ7v8V2BZNVa4Wdky89iqmPz2", MoneroNetworkType.MAINNET);
testInvalidAddress("41ApvrfMgUFZEePHBZHwuSckQXebuZu299NSmVEmQ41YJZQhKcPyujyMSzpDH4VMMVSBo3U3b54JaNvQLwAjqDhKeGLQ9vfRBRKFKnBtVH", MoneroNetworkType.MAINNET);
testInvalidAddress("81fyq3t8Gxn1QWMG189EufHtMHXZXkfJtJKFJXqeA4GpSiuyfjVwVyp47PeQJnD7Tc8iK8TDvvhcmEmfh8nx7Va2ToP8wAo", MoneroNetworkType.MAINNET);
+ testInvalidAddress("4CApvrfMgUFZEePHBZHwuSckQXebuZu299NSmVEmQ41YJZQhKcPyujyMSzpDH4VMMVSBo3U3b54JaNvQLwAjqDhKeGLQ9vf", MoneroNetworkType.MAINNET);
// test invalid addresses on testnet
testInvalidAddress(null, MoneroNetworkType.TESTNET);Why this scored 30/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.