github/copilot-sdk · error · IOException
Invalid ELF program header metadata: phentsize= + phentsize…
Error message
Invalid ELF program header metadata: phentsize= + phentsize + , phnum= + phnum
What it means
Each program header entry must be at least the minimum size for the ELF class (56 bytes for ELF64, 32 for ELF32) and e_phnum must be positive for any PT_INTERP to exist. Values outside these invariants mean a corrupt header or truncated probe, so an IOException is thrown.
Solutions
- Increase the probe size so header-derived reads land on real bytes (probe >= e_phoff + e_phentsize * e_phnum).
- Validate the file with `readelf -l <path>`; if readelf accepts it, your probe is truncated — read more bytes.
- Reinstall/re-download the binary and verify the checksum.
- For untrusted inputs, catch IOException and reject with a clear 'corrupt ELF' message.
Example fix
// before byte[] probe = readHead(path, 128); // too small for many phdrs String interp = readElfPtInterp(probe); // after long fileSize = Files.size(path); byte[] probe = readHead(path, (int) Math.min(fileSize, 65536)); String interp = readElfPtInterp(probe);
Defensive patterns
Strategy: validation
Validate before calling
// phentsize >= 56 (ELF64) or 32 (ELF32) and phnum > 0 for a valid table // ensure probe.length >= phoff + phentsize * phnum before parsing
Try / catch
try {
String interp = readElfPtInterp(probe);
} catch (IOException e) {
throw new IOException("Corrupt or truncated ELF (" + e.getMessage() + "); verify the binary", e);
} Prevention
- Use a probe large enough for the whole program header table.
- Verify binaries with `readelf -l <path>` before shipping.
- Validate checksums after download to catch corruption.
- Reject untrusted ELF inputs via explicit try-catch and clear messages.
When it happens
Trigger: e_phentsize parsed below the class minimum, or e_phnum <= 0 — corrupt ELF header fields, a truncated probe producing garbage offsets/reads, or a mangled download.
Common situations: Binary corruption from transfer or a bad packaging step; probe smaller than the region the header references, so subsequent reads decode garbage; crafted/fuzzed ELF inputs.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Unsupported ELF data encoding: + elfData
- Unsupported ELF class: + elfClass
- Invalid PT_INTERP bounds
- Empty PT_INTERP segment
- ELF probe too small: + size + bytes
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/85f6c0ef2aa5b133.
Report an issue: GitHub.
Appendix: source
Thrown at java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java:202
if (elfClass == ELF_CLASS_64) {
phoff = readUInt64(probe, 32, littleEndian);
phentsize = readUInt16(probe, 54, littleEndian);
phnum = readUInt16(probe, 56, littleEndian);
minimumPhentsize = ELF64_PROGRAM_HEADER_SIZE;
} else if (elfClass == ELF_CLASS_32) {
phoff = readUInt32(probe, 28, littleEndian);
phentsize = readUInt16(probe, 42, littleEndian);
phnum = readUInt16(probe, 44, littleEndian);
minimumPhentsize = ELF32_PROGRAM_HEADER_SIZE;
} else {
throw new IOException("Unsupported ELF class: " + elfClass);
}
if (phoff < 0 || phoff >= size) {
throw new IOException("Program header table offset outside probe window: " + phoff);
}
if (phentsize < minimumPhentsize || phnum <= 0) {
throw new IOException("Invalid ELF program header metadata: phentsize=" + phentsize + ", phnum=" + phnum);
}
for (int i = 0; i < phnum; i++) {
long baseLong = phoff + ((long) i * phentsize);
if (baseLong < 0 || baseLong > Integer.MAX_VALUE) {
break;
}
int base = (int) baseLong;
if (base + phentsize > size) {
break;
}
long pType = readUInt32(probe, base, littleEndian);
if (pType != PT_INTERP) {
continue;
}
long pOffset;View on GitHub (pinned to cd8cf15dc3)