MuntashirAkon/AppManager · error · IOException

Corrupted input, " + name + " value negative

Error message

Corrupted input, " + name + " value negative

What it means

checkBounds is the bzip2 decompressor's central corruption guard: before using any field decoded from the bitstream (nGroups, nSelectors, alphaSize, tt index, etc.) it verifies the value is non-negative and below an exclusive limit. This specific message fires when the decoded value is negative, which can never happen in valid bzip2 data, so the stream is corrupt.

Source

Thrown at app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java:392

        return (int) thech;
    }

    private static boolean bsGetBit(final BitInputStream bin) throws IOException {
        return bsR(bin, 1) != 0;
    }

    private static char bsGetUByte(final BitInputStream bin) throws IOException {
        return (char) bsR(bin, 8);
    }

    private static int bsGetInt(final BitInputStream bin) throws IOException {
        return bsR(bin, 32);
    }

    private static void checkBounds(final int checkVal, final int limitExclusive, final String name)
            throws IOException {
        if (checkVal < 0) {
            throw new IOException("Corrupted input, " + name + " value negative");
        }
        if (checkVal >= limitExclusive) {
            throw new IOException("Corrupted input, " + name + " value too big");
        }
    }

    /**
     * Called by createHuffmanDecodingTables() exclusively.
     */
    private static void hbCreateDecodeTables(final int[] limit,
                                             final int[] base, final int[] perm, final char[] length,
                                             final int minLen, final int maxLen, final int alphaSize)
            throws IOException {
        for (int i = minLen, pp = 0; i <= maxLen; i++) {
            for (int j = 0; j < alphaSize; j++) {
                if (length[j] == i) {
                    perm[pp++] = j;
                }

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Re-obtain or re-download the .bz2 file and verify its integrity (e.g. `bzip2 -t file.bz2`) before decompressing.
  2. Ensure the InputStream actually contains bzip2 data (correct magic 'BZh'); don't feed gzip/zip/plain data.
  3. Close and retry with a fresh, un-consumed InputStream from the original source.
  4. If corrupt-but-recoverable data must be read, catch IOException and skip the damaged member/block rather than treating it as a bug.

Example fix

// before
InputStream in = new FileInputStream(path); // maybe not bzip2
BZip2CompressorInputStream bz = new BZip2CompressorInputStream(in);
// after
try (InputStream in = new BufferedInputStream(Files.newInputStream(path))) {
    if (!looksLikeBzip2(in)) throw new IOException("not a bzip2 file: " + path);
    try (BZip2CompressorInputStream bz = new BZip2CompressorInputStream(in)) {
        // read
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// verify magic before decompressing
try (InputStream in = Files.newInputStream(path)) {
    byte[] magic = in.readNBytes(3);
    if (magic.length < 3 || magic[0] != 'B' || magic[1] != 'Z' || magic[2] != 'h')
        throw new IOException("not bzip2: " + path);
}

Try / catch

try { /* read loop */ } catch (IOException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Corrupted input"))
        throw new CorruptArchiveException(e);
    throw e;
}

Prevention

When it happens

Trigger: Calling BZip2CompressorInputStream.read()/read(byte[],int,int) on a stream whose bitstream yields a negative value for a field checked via checkBounds(name) — e.g. a negative nGroups, nSelectors, alphaSize, tt index, lastShadow, nextSym or yy value decoded from a corrupted/truncated bzip2 block.

Common situations: Reading a bzip2 file that was truncated, corrupted in transfer, or is not actually bzip2 data (wrong file, wrong compression format); piping non-bzip2 bytes into the stream; bit flips on disk or network; feeding a stream already fully consumed.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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