MuntashirAkon/AppManager · error · IOException
Premature end of data
Error message
Premature end of data
What it means
ByteUtils.fromLittleEndian(InputStream,int) reads `length` bytes little-endian from a stream and throws this IOException when the stream ends (read() returns -1) before all requested bytes are consumed — i.e. the data is truncated.
Source
Thrown at app/src/main/java/org/apache/commons/compress/utils/ByteUtils.java:97
}
/**
* Reads the given number of bytes from the given stream as a little endian long.
* @param in the stream to read from
* @param length the number of bytes representing the value
* @return the number read
* @throws IllegalArgumentException if len is bigger than eight
* @throws IOException if reading fails or the stream doesn't
* contain the given number of bytes anymore
*/
public static long fromLittleEndian(final InputStream in, final int length) throws IOException {
// somewhat duplicates the ByteSupplier version in order to save the creation of a wrapper object
checkReadLength(length);
long l = 0;
for (int i = 0; i < length; i++) {
final long b = in.read();
if (b == -1) {
throw new IOException("Premature end of data");
}
l |= (b << (i * 8));
}
return l;
}
/**
* Reads the given number of bytes from the given supplier as a little endian long.
*
* <p>Typically used by our InputStreams that need to count the
* bytes read as well.</p>
*
* @param supplier the supplier for bytes
* @param length the number of bytes representing the value
* @return the number read
* @throws IllegalArgumentException if len is bigger than eight
* @throws IOException if the supplier fails or doesn't supply the
* given number of bytes anymoreView on GitHub (pinned to 0152f468fc)
Solutions
- Check the stream has at least `length` bytes available before reading (or use DataInputStream.readFully with try/catch for EOF)
- Verify the source file/stream integrity and re-transfer if truncated
- Catch IOException and treat as end-of-data / corrupt input, aborting the parse
Example fix
// before
long size = ByteUtils.fromLittleEndian(in, 8); // throws on truncated stream
// after
byte[] buf = new byte[8];
int n = in.readNBytes(buf, 0, 8);
if (n < 8) throw new TruncatedDataException("expected 8 bytes, got " + n);
long size = ByteUtils.fromLittleEndian(buf); Defensive patterns
Strategy: try-catch
Validate before calling
if (in.available() > 0 && in.available() < length) { /* likely truncated: handle before reading */ } Try / catch
try { long v = ByteUtils.fromLittleEndian(in, length); } catch (IOException e) { if (e.getMessage().equals("Premature end of data")) { throw new TruncatedArchiveException("stream ended before " + length + " bytes"); } throw e; } Prevention
- Verify file size/transfer completeness (checksum) before parsing
- Use readNBytes/readFully and check the returned count for clearer diagnostics
- Expect EOF on last-entry boundaries and handle gracefully
When it happens
Trigger: Calling fromLittleEndian(InputStream, length) when fewer than `length` bytes remain before EOF, e.g. reading a fixed-size header from a truncated or corrupt file.
Common situations: Parsing archive headers from truncated downloads; reading past the last entry in a stream; files cut off by transfer interruption.
Related errors
- Detect premature EOF
- Failed to sign
- Could not cache the APK file
- Could not get backup files.
- Could not retrieve metadata from backup.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/7e68671d3e4937a2.
Report an issue: GitHub.