{"record":{"id":"df18fc8783cec424","repo":"MuntashirAkon/AppManager","slug":"unsupported-compression-method-method-in-the-gz-header","errorCode":null,"errorMessage":"Unsupported compression method \" + method + \" in the .gz header","messagePattern":"Unsupported compression method \" \\+ method \\+ \" in the \\.gz header","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java","lineNumber":184,"sourceCode":"        // Check the magic bytes without a possibility of EOFException.\n        final int magic0 = in.read();\n\n        // If end of input was reached after decompressing at least\n        // one .gz member, we have reached the end of the file successfully.\n        if (magic0 == -1 && !isFirstMember) {\n            return false;\n        }\n\n        if (magic0 != 31 || in.read() != 139) {\n            throw new IOException(isFirstMember ? \"Input is not in the .gz format\"\n                    : \"Garbage after a valid .gz stream\");\n        }\n\n        // Parsing the rest of the header may throw EOFException.\n        final DataInput inData = new DataInputStream(in);\n        final int method = inData.readUnsignedByte();\n        if (method != Deflater.DEFLATED) {\n            throw new IOException(\"Unsupported compression method \" + method + \" in the .gz header\");\n        }\n\n        final int flg = inData.readUnsignedByte();\n        if ((flg & FRESERVED) != 0) {\n            throw new IOException(\n                    \"Reserved flags are set in the .gz header\");\n        }\n\n        parameters.setModificationTime(ByteUtils.fromLittleEndian(inData, 4) * 1000);\n        switch (inData.readUnsignedByte()) { // extra flags\n            case 2:\n                parameters.setCompressionLevel(Deflater.BEST_COMPRESSION);\n                break;\n            case 4:\n                parameters.setCompressionLevel(Deflater.BEST_SPEED);\n                break;\n            default:\n                // ignored for now","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java#L166-L202","documentation":"The gzip header's CM (compression method) byte must be 8 (Deflater.DEFLATED). init() reads it and throws IOException if any other method is declared. RFC 1952 currently defines only deflate, so this indicates a malformed or non-standard file.","triggerScenarios":"A .gz header whose byte after the magic numbers is not 8 — corrupted header, custom/experimental compressor, or the stream is actually some other format misaligned by two bytes.","commonSituations":"Corrupted downloads (byte-flips in header); hand-crafted gzip-like files; decoding a foreign format that coincidentally starts with 0x1f 0x8b but uses another method.","solutions":["Recover a pristine copy of the file — the header is corrupt, so re-download or restore from backup.","Check what tool produced the file; recompress with standard gzip/zlib.","Inspect the first ~10 bytes with a hex dump to confirm the file type before parsing."],"exampleFix":"// before\ntry (InputStream gz = new GzipCompressorInputStream(in)) { ... }\n// after\n// validate header first\nbyte[] hdr = new byte[3];\nin.read(hdr);\nif ((hdr[0] & 0xff) != 0x1f || (hdr[1] & 0xff) != 0x8b || hdr[2] != 8) {\n    throw new IOException(\"Not a standard gzip file\");\n}\ntry (InputStream gz = new GzipCompressorInputStream(in)) { ... }","handlingStrategy":"try-catch","validationCode":"// gzip CM byte must be 8 (deflate)\nrawIn.mark(3);\nint cm = readNthByte(rawIn, 2);\nrawIn.reset();\nif (cm != 8) throw new IOException(\"unsupported gzip compression method \" + cm);","typeGuard":null,"tryCatchPattern":"try {\n    InputStream gz = new GzipCompressorInputStream(rawIn);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Unsupported compression method\")) {\n        // treat as corrupt/foreign file: request re-transfer\n    } else {\n        throw e;\n    }\n}","preventionTips":["Only compress with standard tools (gzip, zlib, java.util.zip.Deflater).","Verify transfer integrity with checksums before decompression.","Hex-inspect unrecognized files before parsing them as gzip."],"tags":["gzip","header-validation","corrupt-data"],"backgroundTag":"invalid-enum-value","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"}