MuntashirAkon/AppManager · error · IOException

Reserved flags are set in the .gz header

Error message

Reserved flags are set in the .gz header

What it means

RFC 1952 reserves the top FLG bits (FRESERVED = 0xE0); init() throws IOException if any reserved flag bit is set in the .gz header. This guards against formats that would be parsed incorrectly by this decoder.

Solutions

  1. Recompress the file with standard gzip (or zlib) so reserved flags are zero.
  2. Identify the producing tool — if it legitimately sets reserved bits, decode with that tool instead.
  3. If corruption is suspected, re-transfer and verify with a checksum.

Example fix

// before
InputStream gz = new GzipCompressorInputStream(in);
// after
// recompress source with: gzip -c file > file.gz  (conformant header)
InputStream gz = new GzipCompressorInputStream(in);
Defensive patterns

Strategy: try-catch

Validate before calling

// FLG reserved bits (0xE0) must be zero per RFC 1952
rawIn.mark(4);
int flg = readNthByte(rawIn, 3);
rawIn.reset();
if ((flg & 0xE0) != 0) throw new IOException("reserved gzip flags set");

Try / catch

try {
    InputStream gz = new GzipCompressorInputStream(rawIn);
} catch (IOException e) {
    if (e.getMessage().contains("Reserved flags")) {
        // decompress with the producing tool or recompress with standard gzip
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: A gzip header with FLG having reserved bits set — produced by a non-conforming or future/proprietary compressor, or header corruption.

Common situations: Vendor-specific gzip variants that abuse reserved bits; bit-level corruption in transit; files from custom embedded compressors.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


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

Appendix: source

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

        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
            case 2:
                parameters.setCompressionLevel(Deflater.BEST_COMPRESSION);
                break;
            case 4:
                parameters.setCompressionLevel(Deflater.BEST_SPEED);
                break;
            default:
                // ignored for now
                break;
        }
        parameters.setOperatingSystem(inData.readUnsignedByte());

        // Extra field, ignored

View on GitHub (pinned to 0152f468fc)