{"record":{"id":"34e6af7bdb6c3c04","repo":"MuntashirAkon/AppManager","slug":"gzip-compressed-data-is-corrupt-crc32-error","errorCode":null,"errorMessage":"Gzip-compressed data is corrupt (CRC32 error)","messagePattern":"Gzip-compressed data is corrupt \\(CRC32 error\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java","lineNumber":324,"sourceCode":"            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\n                bufUsed = 0;\n\n                final DataInput inData = new DataInputStream(in);\n\n                // CRC32\n                final long crcStored = ByteUtils.fromLittleEndian(inData, 4);\n\n                if (crcStored != crc.getValue()) {\n                    throw new IOException(\"Gzip-compressed data is corrupt (CRC32 error)\");\n                }\n\n                // Uncompressed size modulo 2^32 (ISIZE in the spec)\n                final long isize = ByteUtils.fromLittleEndian(inData, 4);\n\n                if (isize != (inf.getBytesWritten() & 0xffffffffL)) {\n                    throw new IOException(\"Gzip-compressed data is corrupt (uncompressed size mismatch)\");\n                }\n\n                // See if this is the end of the file.\n                if (!decompressConcatenated || !init(false)) {\n                    inf.end();\n                    inf = null;\n                    endReached = true;\n                    return size == 0 ? -1 : size;\n                }\n            }\n        }","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java#L306-L342","documentation":"Each .gz member ends with a CRC32 of the uncompressed data. read() compares the stored CRC32 with the computed one and throws IOException(\"Gzip-compressed data is corrupt (CRC32 error)\") on mismatch. The deflate stream decoded fine, but the recovered bytes differ from what the compressor recorded.","triggerScenarios":"Bit corruption in compressed or decompressed bytes; an implementation bug producing different bytes; tampered/patched file content while keeping the original trailer.","commonSituations":"Silent disk/network corruption; files edited after compression; faulty pipelines that alter bytes in transit (e.g. text-mode transformations).","solutions":["Re-download/re-extract the file and compare checksums at the transport layer.","Check the pipeline for byte-altering steps (encoding conversions, CRLF translation) and switch to binary-safe transfers.","Restore from a known-good backup if the storage medium is suspect."],"exampleFix":"// before\n// blindly decode\nIOUtils.copy(gz, out);\n// after\ntry {\n    IOUtils.copy(gz, out);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"CRC32\")) {\n        // verify source integrity and re-transfer\n        throw new IOException(\"Corrupt gzip member; re-fetch source\", 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(\"CRC32 error\")) {\n        // decoded bytes do not match the recorded digest — data integrity failure\n        throw new IOException(\"gzip integrity check failed; restore from verified copy\", e);\n    }\n    throw e;\n}","preventionTips":["Verify source checksums before decompressing.","Avoid post-compression edits to archived files; recompress after any change.","Keep binary-safe transfer channels end-to-end."],"tags":["gzip","crc32","corrupt-data","integrity"],"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"}