{"record":{"id":"a772b0890515804f","repo":"MuntashirAkon/AppManager","slug":"gzip-compressed-data-is-corrupt-uncompressed-size-mismatch","errorCode":null,"errorMessage":"Gzip-compressed data is corrupt (uncompressed size mismatch)","messagePattern":"Gzip-compressed data is corrupt \\(uncompressed size mismatch\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java","lineNumber":331,"sourceCode":"                    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        }\n\n        return size;\n    }\n\n    /**\n     * Checks if the signature matches what is expected for a .gz file.\n     *","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java#L313-L349","documentation":"The .gz trailer also stores ISIZE, the uncompressed length modulo 2^32. read() throws IOException when the stored ISIZE differs from the number of bytes the inflater actually produced, meaning the decoded payload length does not match the member's declared size.","triggerScenarios":"Truncated or extended deflate data; a trailer from a different member (mis-joined concatenated members); corruption of the last 8 bytes; custom compressors writing wrong ISIZE.","commonSituations":"Concatenating .gz files by naive byte concatenation without concatenated-mode enabled or with damaged boundaries; interrupted writes leaving a partial member with a stale trailer; non-conforming compression tools.","solutions":["Recover the original file; the member is internally inconsistent and the data cannot be trusted.","If handling concatenated members, enable decompressConcatenated=true so member boundaries are parsed correctly.","Recompress with standard gzip/zlib if a custom tool produced the wrong ISIZE."],"exampleFix":"// before\nGzipCompressorInputStream gz = new GzipCompressorInputStream(in);\n// after (multi-member files)\nGzipCompressorInputStream gz = new GzipCompressorInputStream(in, true);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try (InputStream gz = new GzipCompressorInputStream(rawIn, true)) {\n    IOUtils.copy(gz, out);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"uncompressed size mismatch\")) {\n        // ISIZE disagrees with decoded bytes — treat the archive as damaged\n        throw new IOException(\"gzip member size mismatch; re-acquire archive\", e);\n    }\n    throw e;\n}","preventionTips":["Enable decompressConcatenated=true for files that may be concatenations of .gz members.","Verify archive integrity (gzip -t) before programmatic decompression.","Recompress with standard tools if a custom compressor produced the archive."],"tags":["gzip","isize","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"}