{"record":{"id":"1724b4d6b5ca5a7c","repo":"spring-projects/spring-security","slug":"unable-to-deflate-string","errorCode":null,"errorMessage":"Unable to deflate string","messagePattern":"Unable to deflate string","errorType":"exception","errorClass":"Saml2Exception","httpStatus":null,"severity":"error","filePath":"saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/authentication/Saml2Utils.java","lineNumber":61,"sourceCode":"\n\tstatic String samlEncode(byte[] b) {\n\t\treturn Base64.getEncoder().encodeToString(b);\n\t}\n\n\tstatic byte[] samlDecode(String s) {\n\t\treturn Base64.getMimeDecoder().decode(s);\n\t}\n\n\tstatic byte[] samlDeflate(String s) {\n\t\ttry {\n\t\t\tByteArrayOutputStream b = new ByteArrayOutputStream();\n\t\t\tDeflaterOutputStream deflater = new DeflaterOutputStream(b, new Deflater(Deflater.DEFLATED, true));\n\t\t\tdeflater.write(s.getBytes(StandardCharsets.UTF_8));\n\t\t\tdeflater.finish();\n\t\t\treturn b.toByteArray();\n\t\t}\n\t\tcatch (IOException ex) {\n\t\t\tthrow new Saml2Exception(\"Unable to deflate string\", ex);\n\t\t}\n\t}\n\n\tstatic String samlInflate(byte[] b) {\n\t\ttry {\n\t\t\tByteArrayOutputStream out = new ByteArrayOutputStream();\n\t\t\tInflaterOutputStream iout = new InflaterOutputStream(new CappedOutputStream(out), new Inflater(true));\n\t\t\tiout.write(b);\n\t\t\tiout.finish();\n\t\t\treturn new String(out.toByteArray(), StandardCharsets.UTF_8);\n\t\t}\n\t\tcatch (IOException ex) {\n\t\t\tthrow new Saml2Exception(\"Unable to inflate string\", ex);\n\t\t}\n\t}\n\n\tstatic EncodingConfigurer withDecoded(String decoded) {\n\t\treturn new EncodingConfigurer(decoded);","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/authentication/Saml2Utils.java#L43-L79","documentation":"Saml2Utils.samlDeflate compresses a SAML message string using raw DEFLATE (no zlib/gzip header) for HTTP-Redirect binding. This Saml2Exception is thrown when an IOException occurs during the deflate write/finish, which is practically a JVM-internal I/O failure since the output is an in-memory ByteArrayOutputStream.","triggerScenarios":"samlDeflate(String s) creates a DeflaterOutputStream over a ByteArrayOutputStream and calls write/finish; the catch (IOException ex) branch throws \"Unable to deflate string\" — essentially only on memory exhaustion or unexpected Deflater failure.","commonSituations":"Very large SAML messages causing OutOfMemoryError surfacing as IOException during redirect-binding encoding; JVM resource exhaustion in constrained environments.","solutions":["Retry the operation — this is almost always transient/environmental","Increase JVM heap if deflating very large SAML messages","Check the wrapped cause (ex) for the real underlying failure and fix that","Verify the JVM version for known java.util.zip defects and upgrade"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (samlXml == null || samlXml.isEmpty()) {\n    throw new IllegalArgumentException(\"empty SAML message, skip deflate\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    byte[] deflated = Saml2Utils.samlDeflate(xml);\n} catch (Saml2Exception e) {\n    // inspect cause; treat as transient JVM/resource issue, retry or fail request\n}","preventionTips":["Ensure adequate heap for the largest expected SAML messages","Check wrapped cause before assuming message content is at fault","Retry once on transient failures"],"tags":["saml2","deflate","compression"],"backgroundTag":"compression-failed","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}