{"record":{"id":"5394a939d08ee629","repo":"github/copilot-sdk","slug":"unsupported-elf-data-encoding-elfdata","errorCode":null,"errorMessage":"Unsupported ELF data encoding: + elfData","messagePattern":"Unsupported ELF data encoding: \\+ elfData","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java","lineNumber":176,"sourceCode":"\n    static Set<String> supportedClassifiers() {\n        return SUPPORTED_CLASSIFIERS;\n    }\n\n    private static String readElfPtInterp(byte[] probe) throws IOException {\n        int size = probe.length;\n        if (size < 64) {\n            throw new IOException(\"ELF probe too small: \" + size + \" bytes\");\n        }\n        if ((probe[0] & 0xFF) != ELF_MAGIC_0 || (probe[1] & 0xFF) != ELF_MAGIC_1 || (probe[2] & 0xFF) != ELF_MAGIC_2\n                || (probe[3] & 0xFF) != ELF_MAGIC_3) {\n            throw new IOException(\"Not an ELF executable\");\n        }\n\n        int elfClass = probe[4] & 0xFF;\n        int elfData = probe[5] & 0xFF;\n        if (elfData != ELF_DATA_LITTLE_ENDIAN && elfData != ELF_DATA_BIG_ENDIAN) {\n            throw new IOException(\"Unsupported ELF data encoding: \" + elfData);\n        }\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 {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java#L158-L194","documentation":"Byte 5 of the ELF header (EI_DATA) encodes the data encoding: 1 = little-endian, 2 = big-endian. readElfPtInterp needs the endianness to decode multi-byte header fields; any other value is a corrupt or malformed ELF file, so an IOException is thrown.","triggerScenarios":"The probe's ELF header byte at offset 5 is neither 1 nor 2 — a corrupted binary, a truncated/mangled download, or memory-mismatched bytes in the probe array.","commonSituations":"A binary damaged in transit or by a bad build/packaging step; hand-crafted or fuzzed files fed to the parser; a bad copy where bytes were shifted.","solutions":["Verify the binary integrity (checksum/signature) and reinstall it from a trusted source.","Confirm the file passes `file <path>` and `readelf -h <path>` without EI_DATA complaints.","If parsing user-supplied files, treat this as expected input rejection and surface a clear message rather than a defect.","Check the probe read logic didn't shift/corrupt offsets (read from offset 0 of the file)."],"exampleFix":"// before\nString interp = readElfPtInterp(suspectProbe);\n// after\nint eiData = suspectProbe[5] & 0xFF;\nif (eiData != 1 && eiData != 2) {\n    throw new IOException(\"Corrupt ELF at \" + path + \": EI_DATA=\" + eiData + \", reinstall the binary\");\n}\nString interp = readElfPtInterp(suspectProbe);","handlingStrategy":"validation","validationCode":"// EI_DATA must be 1 (LE) or 2 (BE)\nbyte eiData = probe[5];\nif (eiData != 1 && eiData != 2) throw new IOException(\"Corrupt ELF: EI_DATA=\" + eiData);","typeGuard":null,"tryCatchPattern":"try {\n    String interp = readElfPtInterp(probe);\n} catch (IOException e) {\n    throw new IOException(\"ELF file appears corrupt (\" + e.getMessage() + \"); reinstall the artifact\", e);\n}","preventionTips":["Verify checksums/signatures of binaries after download or build.","Run `readelf -h <path>` in CI to catch corrupted headers before deployment.","Treat parse failures on untrusted files as expected input rejection, not crashes.","Avoid byte-shifting copies (use proper file transfer, not manual buffer surgery)."],"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"}