{"record":{"id":"99d4b1140a19746f","repo":"MuntashirAkon/AppManager","slug":"input-is-not-in-the-gz-format","errorCode":null,"errorMessage":"Input is not in the .gz format","messagePattern":"Input is not in the \\.gz format","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java","lineNumber":176,"sourceCode":"        return parameters;\n    }\n\n    private boolean init(final boolean isFirstMember) throws IOException {\n        if (!isFirstMember && !decompressConcatenated) {\n            throw new IOException(\"Initialised without a first member nor the decompressConcatenated is enabled\");\n        }\n\n        // 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","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java#L158-L194","documentation":"init() reads the first two bytes and expects the gzip magic number 0x1f 0x8b. If they do not match (and it is the first member), it throws IOException(\"Input is not in the .gz format\"). The library validates the container header before any decompression.","triggerScenarios":"Passing a non-gzip stream (plain text, zip, bzip2, truncated/HTML error page) to GzipCompressorInputStream; wrong file extension; reading a decompressed file by mistake.","commonSituations":"Downloading a URL that returned an HTML error page saved as .gz; double-compressed or renamed files; HTTP clients not requesting gzip so the body is plain; streaming pipes where the producer failed.","solutions":["Verify the input really is gzip: check the first two bytes are 0x1f 0x8b before constructing the stream.","Confirm the file/content source; re-download or re-export if it is an error page or different format.","Use CompressorStreamFactory.autoDetectingCompressorInputStream to detect the actual format and pick the right decompressor."],"exampleFix":"// before\nInputStream in = new GzipCompressorInputStream(new FileInputStream(file));\n// after\nInputStream raw = new FileInputStream(file);\nInputStream in = new CompressorStreamFactory().createCompressorInputStream(raw); // auto-detect","handlingStrategy":"validation","validationCode":"rawIn.mark(2);\nint b0 = rawIn.read(), b1 = rawIn.read();\nrawIn.reset();\nif (b0 != 0x1f || b1 != 0x8b) {\n    throw new IOException(\"not a gzip stream (bad magic)\");\n}\nInputStream gz = new GzipCompressorInputStream(rawIn);","typeGuard":null,"tryCatchPattern":"try {\n    InputStream gz = new GzipCompressorInputStream(rawIn);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"not in the .gz format\")) {\n        // fall back to auto-detection or surface 'wrong file type' to the user\n    } else {\n        throw e;\n    }\n}","preventionTips":["Use CompressorStreamFactory auto-detection instead of hardcoding gzip.","Never trust file extensions; validate magic bytes 0x1f 0x8b.","When fetching over HTTP, verify the response content-type/status before saving as .gz."],"tags":["gzip","format-validation","magic-number"],"backgroundTag":"unexpected-response-shape","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"}