{"record":{"id":"c457478f4f13834e","repo":"alibaba/spring-ai-alibaba","slug":"invalid-memory-parameter","errorCode":null,"errorMessage":"Invalid memory parameter","messagePattern":"Invalid memory parameter","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/utils/security/PasswordCryptUtils.java","lineNumber":110,"sourceCode":"\t\tString[] parts = encodedPassword.split(\"\\\\$\");\n\t\tif (parts.length < 4) {\n\t\t\tthrow new IllegalArgumentException(\"Invalid encoded Argon2-hash\");\n\t\t}\n\n\t\tArgon2Parameters.Builder builder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id);\n\n\t\tif (parts[2].startsWith(\"$v=\")) {\n\t\t\tint version = Integer.parseInt(parts[0].substring(2));\n\t\t\tbuilder.withVersion(version);\n\t\t}\n\n\t\tString[] perfParams = parts[3].split(\",\");\n\t\tif (perfParams.length != 3) {\n\t\t\tthrow new IllegalArgumentException(\"Amount of performance parameters invalid\");\n\t\t}\n\n\t\tif (!perfParams[0].startsWith(\"m=\")) {\n\t\t\tthrow new IllegalArgumentException(\"Invalid memory parameter\");\n\t\t}\n\t\tbuilder.withMemoryAsKB(Integer.parseInt(perfParams[0].substring(2)));\n\t\tif (!perfParams[1].startsWith(\"t=\")) {\n\t\t\tthrow new IllegalArgumentException(\"Invalid iterations parameter\");\n\t\t}\n\t\tbuilder.withIterations(Integer.parseInt(perfParams[1].substring(2)));\n\t\tif (!perfParams[2].startsWith(\"p=\")) {\n\t\t\tthrow new IllegalArgumentException(\"Invalid parallel parameter\");\n\t\t}\n\t\tbuilder.withParallelism(Integer.parseInt(perfParams[2].substring(2)));\n\n\t\tbuilder.withSalt(b64decoder.decode(parts[4]));\n\n\t\tbyte[] decoded = b64decoder.decode(parts[5]);\n\t\tbyte[] hashBytes = new byte[decoded.length];\n\n\t\tArgon2BytesGenerator generator = new Argon2BytesGenerator();\n\t\tgenerator.init(builder.build());","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/utils/security/PasswordCryptUtils.java#L92-L128","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before (malformed hash in DB)\n$argon2id$v=19$m65536,t=2,p=1$c2FsdA$aGFzaA==\n// after (correct perf params)\n$argon2id$v=19$m=65536,t=2,p=1$c2FsdA$aGFzaA==","handlingStrategy":"validation","validationCode":"String[] parts = storedHash.split(\"\\\\$\");\nString[] perf = parts[3].split(\",\");\nboolean ok = perf.length == 3 && perf[0].startsWith(\"m=\") && perf[1].startsWith(\"t=\") && perf[2].startsWith(\"p=\");\nif (!ok) throw new IllegalStateException(\"Stored hash perf params malformed: \" + parts[3]);","typeGuard":"static boolean hasValidPerfParams(String hash) {\n    String[] parts = hash.split(\"\\\\$\");\n    if (parts.length < 4) return false;\n    String[] perf = parts[3].split(\",\");\n    return perf.length == 3 && perf[0].startsWith(\"m=\") && perf[1].startsWith(\"t=\") && perf[2].startsWith(\"p=\");\n}","tryCatchPattern":"try {\n    cryptUtils.match(rawPassword, storedHash);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Stored hash malformed: {}\", e.getMessage());\n    throw new AuthenticationException(\"Credential format invalid\");\n}","preventionTips":["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"],"tags":["security","password-hashing","argon2","parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}