LSPosed/LSPosed · error · IllegalArgumentException
Length ${length} is out of range for ${filename}
Error message
Length ${length} is out of range for ${filename} What it means
The same ranged readFile method in DirectAccessService throws IllegalArgumentException when offset + length exceeds the file size (line 99). The implementation allocates byte[length] and does a single fis.read(content), so a length running past EOF would silently return a short read; the API rejects it up front instead.
Source
Thrown at core/src/main/java/de/robv/android/xposed/services/DirectAccessService.java:100
if (length > 0 && (offset + length) > size) {
throw new IllegalArgumentException("Length " + length + " is out of range for " + filename);
} else if (length <= 0) {
length = (int) (size - offset);
}View on GitHub (pinned to df74d83eb0)
Solutions
- Query statFile first and clamp length to (int)(size - offset)
- Pass length <= 0 to mean 'rest of the file' — the implementation then computes length = size - offset itself
- If chunking large files, compute each chunk from the fresh size, not a cached one
Example fix
// before FileResult r = service.readFile(path, offset, 4096, prevSize, prevTime); // after FileResult st = service.statFile(path); int len = (int) Math.min(4096, st.size - offset); FileResult r = service.readFile(path, offset, len, st.size, st.mtime);
Defensive patterns
Strategy: validation
Validate before calling
FileResult st = service.statFile(filename);
if (length > st.size - offset) {
length = (int) (st.size - offset); // clamp to EOF
} Try / catch
try {
return service.readFile(filename, offset, length, prevSize, prevTime);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Length")) {
return service.readFile(filename, offset, 0, prevSize, prevTime); // length<=0 = rest of file
}
throw e;
} Prevention
- Compute chunk lengths from a fresh size, never a cached constant
- Pass length <= 0 when you mean 'to end of file' — the service clamps for you
- Chunk readers should re-stat when (size, mtime) changes
When it happens
Trigger: Calling readFile(path, offset, length, prevSize, prevTime) with length > size - offset, e.g. offset=10, length=100 on a 50-byte file, or when the file shrank between stat and read.
Common situations: Hardcoded chunk sizes for reading structured files whose actual size is smaller than expected; reading with stale cached length after the file was truncated.
Related errors
- Offset ${offset} is out of range for ${filename}
- Error ${errno}${defaultText}${filename}
- hooker should not be null!
- Hooker should be annotated with @XposedHooker
- BeforeInvocation method format is invalid
AI-assisted analysis of LSPosed/LSPosed@df74d83eb0 (2026-08-14).
Data as JSON: /api/errors/5c44490ecb905989.
Report an issue: GitHub.