{"record":{"id":"e6cd7b6595629e59","repo":"MuntashirAkon/AppManager","slug":"gzip-compressed-data-is-corrupt","errorCode":null,"errorMessage":"Gzip-compressed data is corrupt","messagePattern":"Gzip-compressed data is corrupt","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java","lineNumber":297,"sourceCode":"        while (len > 0) {\n            if (inf.needsInput()) {\n                // Remember the current position because we may need to\n                // rewind after reading too much input.\n                in.mark(buf.length);\n\n                bufUsed = in.read(buf);\n                if (bufUsed == -1) {\n                    throw new EOFException();\n                }\n\n                inf.setInput(buf, 0, bufUsed);\n            }\n\n            final int ret;\n            try {\n                ret = inf.inflate(b, off, len);\n            } catch (final DataFormatException e) { // NOSONAR\n                throw new IOException(\"Gzip-compressed data is corrupt\");\n            }\n\n            crc.update(b, off, ret);\n            off += ret;\n            len -= ret;\n            size += ret;\n            count(ret);\n\n            if (inf.finished()) {\n                // We may have read too many bytes. Rewind the read\n                // position to match the actual amount used.\n                in.reset();\n\n                final int skipAmount = bufUsed - inf.getRemaining();\n                if (IOUtils.skip(in, skipAmount) != skipAmount) {\n                    throw new IOException();\n                }\n","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java#L279-L315","documentation":"read() feeds data through java.util.zip.Inflater; when inflate() raises DataFormatException, the deflate stream is malformed and the library rethrows it as IOException(\"Gzip-compressed data is corrupt\"). This is the generic mid-stream corruption/invalid-deflate-data error.","triggerScenarios":"Truncated or bit-corrupted deflate blocks; decoding a file that is not actually deflate-compressed after a valid-looking header; stream read offset desynchronization (e.g. skipped header bytes incorrectly).","commonSituations":"Incomplete downloads/interrupted transfers; decoding multi-part files joined incorrectly; storage media corruption; parsing a .gz whose header parsed but body was replaced.","solutions":["Re-acquire the file and verify a checksum (e.g. md5sum against the source) to confirm corruption.","Check whether the stream is truncated — if the transfer can be retried/range-resumed, redo it.","Wrap reads in try-catch for IOException to fail gracefully and surface the corrupt-input condition to the operator."],"exampleFix":"// before\nInputStream gz = new GzipCompressorInputStream(in);\nIOUtils.copy(gz, out);\n// after\ntry (InputStream gz = new GzipCompressorInputStream(in)) {\n    IOUtils.copy(gz, out);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"corrupt\")) {\n        throw new IOException(\"Source file damaged; re-fetch and verify checksum\", e);\n    }\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try (InputStream gz = new GzipCompressorInputStream(rawIn)) {\n    IOUtils.copy(gz, out);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Gzip-compressed data is corrupt\")) {\n        // input corrupted mid-stream: retry from a verified source, do not retry blindly\n        throw new IOException(\"corrupt gzip payload; re-fetch source\", e);\n    }\n    throw e;\n}","preventionTips":["Verify checksums (md5/sha256) of downloads before decompression.","Ensure transfers are binary-safe (no text-mode/CRLF translation).","Detect truncation: compare file size or use range-verified downloads."],"tags":["gzip","corrupt-data","deflate","checksum"],"backgroundTag":"checksum-mismatch","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}