{"record":{"id":"217ced794cf82fea","repo":"MuntashirAkon/AppManager","slug":"corrupted-input-name-value-negative","errorCode":null,"errorMessage":"Corrupted input, \" + name + \" value negative","messagePattern":"Corrupted input, \" \\+ name \\+ \" value negative","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java","lineNumber":392,"sourceCode":"        return (int) thech;\n    }\n\n    private static boolean bsGetBit(final BitInputStream bin) throws IOException {\n        return bsR(bin, 1) != 0;\n    }\n\n    private static char bsGetUByte(final BitInputStream bin) throws IOException {\n        return (char) bsR(bin, 8);\n    }\n\n    private static int bsGetInt(final BitInputStream bin) throws IOException {\n        return bsR(bin, 32);\n    }\n\n    private static void checkBounds(final int checkVal, final int limitExclusive, final String name)\n            throws IOException {\n        if (checkVal < 0) {\n            throw new IOException(\"Corrupted input, \" + name + \" value negative\");\n        }\n        if (checkVal >= limitExclusive) {\n            throw new IOException(\"Corrupted input, \" + name + \" value too big\");\n        }\n    }\n\n    /**\n     * Called by createHuffmanDecodingTables() exclusively.\n     */\n    private static void hbCreateDecodeTables(final int[] limit,\n                                             final int[] base, final int[] perm, final char[] length,\n                                             final int minLen, final int maxLen, final int alphaSize)\n            throws IOException {\n        for (int i = minLen, pp = 0; i <= maxLen; i++) {\n            for (int j = 0; j < alphaSize; j++) {\n                if (length[j] == i) {\n                    perm[pp++] = j;\n                }","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java#L374-L410","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-obtain or re-download the .bz2 file and verify its integrity (e.g. `bzip2 -t file.bz2`) before decompressing.","Ensure the InputStream actually contains bzip2 data (correct magic 'BZh'); don't feed gzip/zip/plain data.","Close and retry with a fresh, un-consumed InputStream from the original source.","If corrupt-but-recoverable data must be read, catch IOException and skip the damaged member/block rather than treating it as a bug."],"exampleFix":"// before\nInputStream in = new FileInputStream(path); // maybe not bzip2\nBZip2CompressorInputStream bz = new BZip2CompressorInputStream(in);\n// after\ntry (InputStream in = new BufferedInputStream(Files.newInputStream(path))) {\n    if (!looksLikeBzip2(in)) throw new IOException(\"not a bzip2 file: \" + path);\n    try (BZip2CompressorInputStream bz = new BZip2CompressorInputStream(in)) {\n        // read\n    }\n}","handlingStrategy":"try-catch","validationCode":"// verify magic before decompressing\ntry (InputStream in = Files.newInputStream(path)) {\n    byte[] magic = in.readNBytes(3);\n    if (magic.length < 3 || magic[0] != 'B' || magic[1] != 'Z' || magic[2] != 'h')\n        throw new IOException(\"not bzip2: \" + path);\n}","typeGuard":null,"tryCatchPattern":"try { /* read loop */ } catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Corrupted input\"))\n        throw new CorruptArchiveException(e);\n    throw e;\n}","preventionTips":["Verify archives with `bzip2 -t` before processing","Feed only BufferedInputStream over the original file, never partial copies","Treat IOException during decompression as data corruption, not a code bug","Keep commons-compress updated for the latest hardening checks"],"tags":["io","bzip2","corrupt-input","decompression"],"backgroundTag":"invalid-argument-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}