{"record":{"id":"d11f95568eaf78d9","repo":"MuntashirAkon/AppManager","slug":"count-must-not-be-negative-or-greater-than-maximum-cache","errorCode":null,"errorMessage":"count must not be negative or greater than \" + MAXIMUM_CACHE_SIZE","messagePattern":"count must not be negative or greater than \" \\+ MAXIMUM_CACHE_SIZE","errorType":"validation","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/utils/BitInputStream.java","lineNumber":68,"sourceCode":"     */\n    public void clearBitCache() {\n        bitsCached = 0;\n        bitsCachedSize = 0;\n    }\n\n    /**\n     * Returns at most 63 bits read from the underlying stream.\n     *\n     * @param count the number of bits to read, must be a positive\n     * number not bigger than 63.\n     * @return the bits concatenated as a long using the stream's byte order.\n     *         -1 if the end of the underlying stream has been reached before reading\n     *         the requested number of bits\n     * @throws IOException on error\n     */\n    public long readBits(final int count) throws IOException {\n        if (count < 0 || count > MAXIMUM_CACHE_SIZE) {\n            throw new IOException(\"count must not be negative or greater than \" + MAXIMUM_CACHE_SIZE);\n        }\n        if (ensureCache(count)) {\n            return -1;\n        }\n\n        if (bitsCachedSize < count) {\n            return processBitsGreater57(count);\n        }\n        return readCachedBits(count);\n    }\n\n    /**\n     * Returns the number of bits that can be read from this input\n     * stream without reading from the underlying input stream at all.\n     * @return estimate of the number of bits that can be read without reading from the underlying stream\n     * @since 1.16\n     */\n    public int bitsCached() {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/utils/BitInputStream.java#L50-L86","documentation":"BitInputStream.readBits validates the requested bit count before reading: count must be between 0 and MAXIMUM_CACHE_SIZE (63, the max bits fitting in a long cache). Out-of-range counts throw an IOException because the implementation cannot serve them.","triggerScenarios":"Calling readBits(count) with a negative count or count > 63, e.g. requesting 64+ bits at once or passing an unvalidated field-width from a header.","commonSituations":"Attempting to read 64-bit values in one call from a bit-oriented format; passing a signed byte as a bit count; malformed archive format metadata specifying an oversized field.","solutions":["Request at most 63 bits per call; split a 64-bit read into two calls and combine results","Validate/clamp the count parameter before calling readBits","Read a full byte via readBits(8) and compose larger values manually"],"exampleFix":"// before\nlong v = bitStream.readBits(64); // IOException\n// after\nlong lo = bitStream.readBits(32);\nlong hi = bitStream.readBits(32);\nlong v = (hi << 32) | lo;","handlingStrategy":"validation","validationCode":"if (count < 0 || count > 63) throw new IllegalArgumentException(\"readBits count must be 0..63, got \" + count);","typeGuard":null,"tryCatchPattern":"try { long v = bits.readBits(count); } catch (IOException e) { if (e.getMessage().startsWith(\"count must not be\")) throw new IllegalArgumentException(e.getMessage(), e); throw e; }","preventionTips":["Never request more than 63 bits per call","Split 64-bit fields into two reads and combine","Validate format-defined field widths against the 63-bit limit at parse start"],"tags":["bitstream","io","argument-validation"],"backgroundTag":"value-out-of-range","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"}