MuntashirAkon/AppManager · error · IOException

Input is not in the .gz format

Error message

Input is not in the .gz format

What it means

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.

Solutions

  1. Verify the input really is gzip: check the first two bytes are 0x1f 0x8b before constructing the stream.
  2. Confirm the file/content source; re-download or re-export if it is an error page or different format.
  3. Use CompressorStreamFactory.autoDetectingCompressorInputStream to detect the actual format and pick the right decompressor.

Example fix

// before
InputStream in = new GzipCompressorInputStream(new FileInputStream(file));
// after
InputStream raw = new FileInputStream(file);
InputStream in = new CompressorStreamFactory().createCompressorInputStream(raw); // auto-detect
Defensive patterns

Strategy: validation

Validate before calling

rawIn.mark(2);
int b0 = rawIn.read(), b1 = rawIn.read();
rawIn.reset();
if (b0 != 0x1f || b1 != 0x8b) {
    throw new IOException("not a gzip stream (bad magic)");
}
InputStream gz = new GzipCompressorInputStream(rawIn);

Try / catch

try {
    InputStream gz = new GzipCompressorInputStream(rawIn);
} catch (IOException e) {
    if (e.getMessage().contains("not in the .gz format")) {
        // fall back to auto-detection or surface 'wrong file type' to the user
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Passing a non-gzip stream (plain text, zip, bzip2, truncated/HTML error page) to GzipCompressorInputStream; wrong file extension; reading a decompressed file by mistake.

Common situations: 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.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/99d4b1140a19746f. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java:176

        return parameters;
    }

    private boolean init(final boolean isFirstMember) throws IOException {
        if (!isFirstMember && !decompressConcatenated) {
            throw new IOException("Initialised without a first member nor the decompressConcatenated is enabled");
        }

        // Check the magic bytes without a possibility of EOFException.
        final int magic0 = in.read();

        // If end of input was reached after decompressing at least
        // one .gz member, we have reached the end of the file successfully.
        if (magic0 == -1 && !isFirstMember) {
            return false;
        }

        if (magic0 != 31 || in.read() != 139) {
            throw new IOException(isFirstMember ? "Input is not in the .gz format"
                    : "Garbage after a valid .gz stream");
        }

        // Parsing the rest of the header may throw EOFException.
        final DataInput inData = new DataInputStream(in);
        final int method = inData.readUnsignedByte();
        if (method != Deflater.DEFLATED) {
            throw new IOException("Unsupported compression method " + method + " in the .gz header");
        }

        final int flg = inData.readUnsignedByte();
        if ((flg & FRESERVED) != 0) {
            throw new IOException(
                    "Reserved flags are set in the .gz header");
        }

        parameters.setModificationTime(ByteUtils.fromLittleEndian(inData, 4) * 1000);
        switch (inData.readUnsignedByte()) { // extra flags

View on GitHub (pinned to 0152f468fc)