MuntashirAkon/AppManager · error · IllegalArgumentException
Block size must be a multiple of 512 bytes. Attempt to use s
Error message
Block size must be a multiple of 512 bytes. Attempt to use set size of ${blockSize} What it means
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.
Source
Thrown at app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java:204
/**
* Constructor for TarArchiveOutputStream.
*
* @param os the output stream to use
* @param blockSize the block size to use. Must be a multiple of 512 bytes.
* @param encoding name of the encoding to use for file names
* @since 1.4
*/
public TarArchiveOutputStream(final OutputStream os, final int blockSize,
final String encoding) {
final int realBlockSize;
if (BLOCK_SIZE_UNSPECIFIED == blockSize) {
realBlockSize = RECORD_SIZE;
} else {
realBlockSize = blockSize;
}
if (realBlockSize <=0 || realBlockSize % RECORD_SIZE != 0) {
throw new IllegalArgumentException("Block size must be a multiple of 512 bytes. Attempt to use set size of " + blockSize);
}
out = new FixedLengthBlockOutputStream(countingOut = new CountingOutputStream(os),
RECORD_SIZE);
this.encoding = encoding;
this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding);
this.recordBuf = new byte[RECORD_SIZE];
this.recordsPerBlock = realBlockSize / RECORD_SIZE;
}
/**
* Set the long file mode. This can be LONGFILE_ERROR(0), LONGFILE_TRUNCATE(1) or
* LONGFILE_GNU(2). This specifies the treatment of long file names (names >=
* TarConstants.NAMELEN). Default is LONGFILE_ERROR.
*
* @param longFileMode the mode to use
*/
public void setLongFileMode(final int longFileMode) {View on GitHub (pinned to 0152f468fc)
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.
Example fix
// before new TarArchiveOutputStream(out, 1000, "UTF-8"); // throws // after int blockSize = 10240; // multiple of 512 new TarArchiveOutputStream(out, blockSize, "UTF-8");
Defensive patterns
Strategy: validation
Validate before calling
if (blockSize <= 0 || blockSize % 512 != 0) throw new IllegalArgumentException("blockSize must be a positive multiple of 512"); Try / catch
try {
os = new TarArchiveOutputStream(out, cfg.getBlockSize(), enc);
} catch (IllegalArgumentException e) {
os = new TarArchiveOutputStream(out, 10240, enc); // safe default
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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).
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Tar record size must always be 512 bytes. Attempt to set siz
- blockSize(" + blockSize + ") < 1
- The app has keystore items and KeyStore backup isn't enabled
- APK files backup is requested but no source directory has be
- Failed to backup data directory at
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/df9c0f9afb7eb6ba.
Report an issue: GitHub.