{"record":{"id":"df9c0f9afb7eb6ba","repo":"MuntashirAkon/AppManager","slug":"block-size-must-be-a-multiple-of-512-bytes-attempt-to-use","errorCode":null,"errorMessage":"Block size must be a multiple of 512 bytes. Attempt to use set size of ${blockSize}","messagePattern":"Block size must be a multiple of 512 bytes\\. Attempt to use set size of (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java","lineNumber":204,"sourceCode":"    /**\n     * Constructor for TarArchiveOutputStream.\n     *\n     * @param os the output stream to use\n     * @param blockSize the block size to use. Must be a multiple of 512 bytes.\n     * @param encoding name of the encoding to use for file names\n     * @since 1.4\n     */\n    public TarArchiveOutputStream(final OutputStream os, final int blockSize,\n        final String encoding) {\n        final int realBlockSize;\n        if (BLOCK_SIZE_UNSPECIFIED == blockSize) {\n            realBlockSize = RECORD_SIZE;\n        } else {\n            realBlockSize = blockSize;\n        }\n\n        if (realBlockSize <=0 || realBlockSize % RECORD_SIZE != 0) {\n            throw new IllegalArgumentException(\"Block size must be a multiple of 512 bytes. Attempt to use set size of \" + blockSize);\n        }\n        out = new FixedLengthBlockOutputStream(countingOut = new CountingOutputStream(os),\n                                               RECORD_SIZE);\n        this.encoding = encoding;\n        this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding);\n\n        this.recordBuf = new byte[RECORD_SIZE];\n        this.recordsPerBlock = realBlockSize / RECORD_SIZE;\n    }\n\n    /**\n     * Set the long file mode. This can be LONGFILE_ERROR(0), LONGFILE_TRUNCATE(1) or\n     * LONGFILE_GNU(2). This specifies the treatment of long file names (names &gt;=\n     * TarConstants.NAMELEN). Default is LONGFILE_ERROR.\n     *\n     * @param longFileMode the mode to use\n     */\n    public void setLongFileMode(final int longFileMode) {","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java#L186-L222","documentation":"TarArchiveOutputStream requires the block size to be a positive multiple of the 512-byte tar record size. A non-positive or non-multiple value is rejected with an IllegalArgumentException before any output is written.","triggerScenarios":"Constructing TarArchiveOutputStream with blockSize <= 0 or blockSize % 512 != 0, e.g. blockSize=1000 or 0 (values below 512 are clamped to 512, but 513..1023 fail).","commonSituations":"Using block sizes copied from other archive tools (e.g. 10240 is fine, 8192 is not since 8192 is a multiple — 4096 is not? it is not: 4096/512=8, so fine; typical failures are odd sizes like 1KB+512 offsets or 0/negative values from config files).","solutions":["Use a blockSize that is a positive multiple of 512 (512, 1024, 10240 are common).","Omit the blockSize parameter and use a constructor default.","Validate any user/config-supplied block size with blockSize > 0 && blockSize % 512 == 0 before constructing the stream."],"exampleFix":"// before\nnew TarArchiveOutputStream(out, 1000, \"UTF-8\"); // throws\n// after\nint blockSize = 10240; // multiple of 512\nnew TarArchiveOutputStream(out, blockSize, \"UTF-8\");","handlingStrategy":"validation","validationCode":"if (blockSize <= 0 || blockSize % 512 != 0) throw new IllegalArgumentException(\"blockSize must be a positive multiple of 512\");","typeGuard":null,"tryCatchPattern":"try {\n    os = new TarArchiveOutputStream(out, cfg.getBlockSize(), enc);\n} catch (IllegalArgumentException e) {\n    os = new TarArchiveOutputStream(out, 10240, enc); // safe default\n}","preventionTips":["Clamp/round user-supplied block sizes to the next multiple of 512","Prefer constructor defaults when block size is not critical","Validate config values at startup"],"tags":["tar","illegal-argument","block-size","configuration"],"backgroundTag":"invalid-config-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}