{"record":{"id":"e67a5a65c5520c19","repo":"github/copilot-sdk","slug":"unsupported-elf-class-elfclass","errorCode":null,"errorMessage":"Unsupported ELF class: + elfClass","messagePattern":"Unsupported ELF class: \\+ elfClass","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java","lineNumber":195,"sourceCode":"        }\n        boolean littleEndian = elfData == ELF_DATA_LITTLE_ENDIAN;\n\n        long phoff;\n        int phentsize;\n        int phnum;\n        int minimumPhentsize;\n        if (elfClass == ELF_CLASS_64) {\n            phoff = readUInt64(probe, 32, littleEndian);\n            phentsize = readUInt16(probe, 54, littleEndian);\n            phnum = readUInt16(probe, 56, littleEndian);\n            minimumPhentsize = ELF64_PROGRAM_HEADER_SIZE;\n        } else if (elfClass == ELF_CLASS_32) {\n            phoff = readUInt32(probe, 28, littleEndian);\n            phentsize = readUInt16(probe, 42, littleEndian);\n            phnum = readUInt16(probe, 44, littleEndian);\n            minimumPhentsize = ELF32_PROGRAM_HEADER_SIZE;\n        } else {\n            throw new IOException(\"Unsupported ELF class: \" + elfClass);\n        }\n\n        if (phoff < 0 || phoff >= size) {\n            throw new IOException(\"Program header table offset outside probe window: \" + phoff);\n        }\n        if (phentsize < minimumPhentsize || phnum <= 0) {\n            throw new IOException(\"Invalid ELF program header metadata: phentsize=\" + phentsize + \", phnum=\" + phnum);\n        }\n\n        for (int i = 0; i < phnum; i++) {\n            long baseLong = phoff + ((long) i * phentsize);\n            if (baseLong < 0 || baseLong > Integer.MAX_VALUE) {\n                break;\n            }\n            int base = (int) baseLong;\n            if (base + phentsize > size) {\n                break;\n            }","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java#L177-L213","documentation":"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.","triggerScenarios":"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.","commonSituations":"Binary damaged by transfer/build packaging; fuzzed or crafted input files; byte-level corruption from a bad copy or failed patch.","solutions":["Reinstall/re-download the binary and verify its checksum — a valid ELF always has EI_CLASS 1 or 2.","Validate with `readelf -h <path>`; if readelf rejects it, the file is corrupt.","If parsing untrusted files, catch IOException and reject the input with a clear message.","Ensure the probe bytes weren't shifted by an incorrect read offset."],"exampleFix":"// before\nString interp = readElfPtInterp(probe);\n// after\nint eiClass = probe[4] & 0xFF;\nif (eiClass != 1 && eiClass != 2) {\n    throw new IOException(\"Corrupt ELF at \" + path + \": EI_CLASS=\" + eiClass);\n}\nString interp = readElfPtInterp(probe);","handlingStrategy":"validation","validationCode":"byte eiClass = probe[4];\nif (eiClass != 1 && eiClass != 2) throw new IOException(\"Corrupt ELF: EI_CLASS=\" + eiClass);","typeGuard":null,"tryCatchPattern":"try {\n    String interp = readElfPtInterp(probe);\n} catch (IOException e) {\n    throw new IOException(\"ELF header corrupt (\" + e.getMessage() + \"); artifact integrity check failed\", e);\n}","preventionTips":["Verify artifact checksums after install.","Run `readelf -h <path>` as a pre-flight sanity check in CI.","Reject untrusted/crafted ELF inputs explicitly via try-catch.","Never mutate or re-pack binaries with custom tooling that can corrupt header bytes."],"tags":["elf","binary-parsing","corruption","java"],"backgroundTag":"invalid-argument-format","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}