github/copilot-sdk · error · IOException

Unsupported ELF class: + elfClass

Error message

Unsupported ELF class: + elfClass

What it means

Byte 4 of the ELF header (EI_CLASS) must be 1 (ELF32) or 2 (ELF64). readElfPtInterp uses it to select header layout offsets for the program header table; any other value means the file is corrupt or not really ELF, so an IOException is thrown.

Solutions

  1. Reinstall/re-download the binary and verify its checksum — a valid ELF always has EI_CLASS 1 or 2.
  2. Validate with `readelf -h <path>`; if readelf rejects it, the file is corrupt.
  3. If parsing untrusted files, catch IOException and reject the input with a clear message.
  4. Ensure the probe bytes weren't shifted by an incorrect read offset.

Example fix

// before
String interp = readElfPtInterp(probe);
// after
int eiClass = probe[4] & 0xFF;
if (eiClass != 1 && eiClass != 2) {
    throw new IOException("Corrupt ELF at " + path + ": EI_CLASS=" + eiClass);
}
String interp = readElfPtInterp(probe);
Defensive patterns

Strategy: validation

Validate before calling

byte eiClass = probe[4];
if (eiClass != 1 && eiClass != 2) throw new IOException("Corrupt ELF: EI_CLASS=" + eiClass);

Try / catch

try {
    String interp = readElfPtInterp(probe);
} catch (IOException e) {
    throw new IOException("ELF header corrupt (" + e.getMessage() + "); artifact integrity check failed", e);
}

Prevention

When it happens

Trigger: The probe's ELF header byte at offset 4 is not 1 or 2 — a corrupted binary, mangled download, or a fake file that has valid magic but garbage EI_CLASS.

Common situations: Binary damaged by transfer/build packaging; fuzzed or crafted input files; byte-level corruption from a bad copy or failed patch.

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


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/e67a5a65c5520c19. Report an issue: GitHub.

Appendix: source

Thrown at java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java:195

        }
        boolean littleEndian = elfData == ELF_DATA_LITTLE_ENDIAN;

        long phoff;
        int phentsize;
        int phnum;
        int minimumPhentsize;
        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;
            }

View on GitHub (pinned to cd8cf15dc3)