{"record":{"id":"1985cfa084de935b","repo":"MuntashirAkon/AppManager","slug":"exceptionmessage-buffer-offset-length-start-currentbyte","errorCode":null,"errorMessage":"${exceptionMessage(buffer, offset, length, start, currentByte)}","messagePattern":"\\$\\{exceptionMessage\\(buffer, offset, length, start, currentByte\\)\\}","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java","lineNumber":136,"sourceCode":"                break;\n            }\n        }\n\n        // Trim all trailing NULs and spaces.\n        // The ustar and POSIX tar specs require a trailing NUL or\n        // space but some implementations use the extra digit for big\n        // sizes/uids/gids ...\n        byte trailer = buffer[end - 1];\n        while (start < end && (trailer == 0 || trailer == ' ')) {\n            end--;\n            trailer = buffer[end - 1];\n        }\n\n        for ( ;start < end; start++) {\n            final byte currentByte = buffer[start];\n            // CheckStyle:MagicNumber OFF\n            if (currentByte < '0' || currentByte > '7'){\n                throw new IllegalArgumentException(\n                        exceptionMessage(buffer, offset, length, start, currentByte));\n            }\n            result = (result << 3) + (currentByte - '0'); // convert from ASCII\n            // CheckStyle:MagicNumber ON\n        }\n\n        return result;\n    }\n\n    /**\n     * Compute the value contained in a byte buffer.  If the most\n     * significant bit of the first byte in the buffer is set, this\n     * bit is ignored and the rest of the buffer is interpreted as a\n     * binary number.  Otherwise, the buffer is interpreted as an\n     * octal number as per the parseOctal function above.\n     *\n     * @param buffer The buffer from which to parse.\n     * @param offset The offset into the buffer from which to parse.","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java#L118-L154","documentation":"TarUtils.parseOctal throws this IllegalArgumentException when it encounters a byte that is not an ASCII octal digit ('0'-'7') inside the numeric field. exceptionMessage() builds a human-readable string showing the offending byte and position. This means the tar header field is not valid octal — typically because the archive uses GNU base-256 binary encoding, or the header is corrupt.","triggerScenarios":"Parsing a tar created with GNU base-256 encoding (values >= 8GB, or negative sizes) using plain parseOctal instead of parseOctalOrBinary; corrupted archives with garbage in size/mtime/checksum fields.","commonSituations":"Reading GNU tar archives with very large files through code that assumes pure octal headers; manually implemented tar parsers; truncated or bit-rotted archive files.","solutions":["Call TarUtils.parseOctalOrBinary(buffer, offset, length) instead of parseOctal — it handles both octal and base-256 binary fields","Re-download/re-extract the archive if the source is corrupted (verify with tar -tf or checksums first)","If you must keep parseOctal, pre-check for the base-256 marker byte (buffer[offset] & 0x80) != 0 and route to binary parsing","Check the field offset/length against the tar spec in case you are parsing the wrong bytes"],"exampleFix":"// before\nlong size = TarUtils.parseOctal(header, offset, TarConstants.SIZELEN);\n// after\nlong size = TarUtils.parseOctalOrBinary(header, offset, TarConstants.SIZELEN);","handlingStrategy":"validation","validationCode":"public static long safeParseNumeric(byte[] buffer, int offset, int length) {\n    if (length >= 1 && (buffer[offset] & 0x80) != 0) {\n        return TarUtils.parseOctalOrBinary(buffer, offset, length); // base-256 GNU field\n    }\n    return TarUtils.parseOctal(buffer, offset, length);\n}","typeGuard":"static boolean isBase256Field(byte[] buffer, int offset) {\n    return offset < buffer.length && (buffer[offset] & 0x80) != 0;\n}","tryCatchPattern":"try {\n    long size = TarUtils.parseOctal(header, offset, TarConstants.SIZELEN);\n} catch (IllegalArgumentException e) {\n    // invalid digit — probably GNU base-256 or corrupt data\n    size = TarUtils.parseOctalOrBinary(header, offset, TarConstants.SIZELEN);\n}","preventionTips":["Default to parseOctalOrBinary, not parseOctal — it handles both encodings","Check the first field byte for the 0x80 base-256 marker before parsing","Verify archive integrity (checksums) before parsing headers from untrusted sources","Validate the extracted values against sane ranges before using them as sizes/offsets"],"tags":["java","tar","octal","corrupt-data"],"backgroundTag":"invalid-argument-format","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"}