alibaba/spring-ai-alibaba · error · IllegalArgumentException
Invalid memory parameter
Error message
Invalid memory parameter
What it means
PasswordCryptUtils.match() parses a PHC-style hashed password string and validates the performance-parameters segment (parts[3], e.g. 'm=65536,t=2,p=1'). It splits that segment on commas, requires exactly 3 items, and requires the first item to start with 'm='. If the memory parameter is missing or malformed, it throws this IllegalArgumentException.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/utils/security/PasswordCryptUtils.java:110
String[] parts = encodedPassword.split("\\$");
if (parts.length < 4) {
throw new IllegalArgumentException("Invalid encoded Argon2-hash");
}
Argon2Parameters.Builder builder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id);
if (parts[2].startsWith("$v=")) {
int version = Integer.parseInt(parts[0].substring(2));
builder.withVersion(version);
}
String[] perfParams = parts[3].split(",");
if (perfParams.length != 3) {
throw new IllegalArgumentException("Amount of performance parameters invalid");
}
if (!perfParams[0].startsWith("m=")) {
throw new IllegalArgumentException("Invalid memory parameter");
}
builder.withMemoryAsKB(Integer.parseInt(perfParams[0].substring(2)));
if (!perfParams[1].startsWith("t=")) {
throw new IllegalArgumentException("Invalid iterations parameter");
}
builder.withIterations(Integer.parseInt(perfParams[1].substring(2)));
if (!perfParams[2].startsWith("p=")) {
throw new IllegalArgumentException("Invalid parallel parameter");
}
builder.withParallelism(Integer.parseInt(perfParams[2].substring(2)));
builder.withSalt(b64decoder.decode(parts[4]));
byte[] decoded = b64decoder.decode(parts[5]);
byte[] hashBytes = new byte[decoded.length];
Argon2BytesGenerator generator = new Argon2BytesGenerator();
generator.init(builder.build());View on GitHub (pinned to f82da0b50f)
Solutions
- Verify the stored hash string has the full 6-part format: $argon2id$v=19$m=...,t=...,p=...$salt$hash
- Fix or regenerate the stored hash with the same PasswordCryptUtils.encode() used at signup
- Log the raw stored hash (parts[3]) to confirm which segment is malformed before re-writing it
Example fix
// before (malformed hash in DB) $argon2id$v=19$m65536,t=2,p=1$c2FsdA$aGFzaA== // after (correct perf params) $argon2id$v=19$m=65536,t=2,p=1$c2FsdA$aGFzaA==
Defensive patterns
Strategy: validation
Validate before calling
String[] parts = storedHash.split("\\$");
String[] perf = parts[3].split(",");
boolean ok = perf.length == 3 && perf[0].startsWith("m=") && perf[1].startsWith("t=") && perf[2].startsWith("p=");
if (!ok) throw new IllegalStateException("Stored hash perf params malformed: " + parts[3]); Type guard
static boolean hasValidPerfParams(String hash) {
String[] parts = hash.split("\\$");
if (parts.length < 4) return false;
String[] perf = parts[3].split(",");
return perf.length == 3 && perf[0].startsWith("m=") && perf[1].startsWith("t=") && perf[2].startsWith("p=");
} Try / catch
try {
cryptUtils.match(rawPassword, storedHash);
} catch (IllegalArgumentException e) {
log.warn("Stored hash malformed: {}", e.getMessage());
throw new AuthenticationException("Credential format invalid");
} Prevention
- Only ever generate hashes with the same PasswordCryptUtils.encode() used for verification
- Add a regex check on the PHC format when persisting hashes
- Guard DB migrations that copy hash columns between schemas
When it happens
Trigger: Calling match(rawPassword, storedHash) where the stored hash's 4th colon-separated part does not contain three comma-separated params, or its first param is not prefixed with 'm=' (e.g. 'm65536,t=2,p=1' or a hash produced by a different format).
Common situations: Stored hashes written by another library or an older format, hashes hand-edited or truncated in the database, or hashes migrated from a system using a different PHC serialization.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Invalid iterations parameter
- Invalid parallel parameter
- Invalid encoded Argon2-hash
- Amount of performance parameters invalid
- parse default-default-application.yml failed
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/c457478f4f13834e.
Report an issue: GitHub.