{"record":{"id":"e7ec364d9690e634","repo":"github/copilot-sdk","slug":"elf-probe-too-small-size-bytes","errorCode":null,"errorMessage":"ELF probe too small: + size +  bytes","messagePattern":"ELF probe too small: \\+ size \\+  bytes","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java","lineNumber":166,"sourceCode":"\n    static String detectClassifier(String os, String arch, LinuxLibc linuxLibc) {\n        LinuxLibc classifierLibc = \"linux\".equals(os) ? linuxLibc : LinuxLibc.UNKNOWN;\n        String classifier = CLASSIFIER_BY_KEY.get(new ClassifierKey(os, arch, classifierLibc));\n        if (classifier == null || !SUPPORTED_CLASSIFIERS.contains(classifier)) {\n            throw new IllegalStateException(\n                    \"Unsupported platform tuple: os=\" + os + \", arch=\" + arch + \", libc=\" + classifierLibc);\n        }\n        return classifier;\n    }\n\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) {","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java#L148-L184","documentation":"readElfPtInterp parses the ELF header and program headers from a small byte probe read from an executable to find PT_INTERP. A probe smaller than 64 bytes cannot even hold the ELF header, so parsing is impossible and an IOException is thrown. This indicates the probe read was truncated or the file is not a real ELF binary.","triggerScenarios":"Interpreter resolution reads fewer than 64 bytes from the target file: the file is shorter than 64 bytes (corrupt/placeholder file), the probe read is truncated by a size limit or partial read, or the 'executable' is actually a script/symlink stub with tiny content.","commonSituations":"A broken install where the native binary is a 0-byte or truncated file; a probe-size constant set too small after a refactor; pointing the resolver at a text wrapper script instead of the ELF binary; a corrupted download.","solutions":["Increase the probe read size to at least 64 bytes (in practice the constant the library uses, typically 4096+, so PT_INTERP is covered too).","Verify the target file is a complete ELF binary (file <path> should report 'ELF 64-bit ...'; re-download/reinstall if truncated).","Ensure the resolver is pointed at the real native executable, not a shell wrapper, symlink to a script, or placeholder.","Check disk space / read errors that could cause a partial read of the file head."],"exampleFix":"// before\nbyte[] probe = new byte[16];\ntry (InputStream in = Files.newInputStream(path)) { in.read(probe); }\n// after\nbyte[] probe = new byte[4096];\ntry (InputStream in = Files.newInputStream(path)) {\n    int n = in.readNBytes(probe, 0, probe.length);\n    if (n < 64) throw new IOException(\"Truncated ELF header in \" + path);\n}","handlingStrategy":"validation","validationCode":"if (Files.size(binaryPath) < 64) {\n    throw new IOException(binaryPath + \" is truncated/corrupt (<64 bytes)\");\n}","typeGuard":"static boolean looksLikeEligibleBinary(Path p) throws IOException {\n    return Files.isRegularFile(p) && Files.size(p) >= 64;\n}","tryCatchPattern":"try {\n    String interp = resolveInterpreter(binaryPath);\n} catch (IOException e) {\n    throw new IOException(\"Cannot read ELF interpreter from \" + binaryPath + \": \" + e.getMessage()\n        + \"; reinstall the native binary\", e);\n}","preventionTips":["Verify artifact checksums after download/install to catch truncated binaries early.","Probe with a large head read (>= 4KiB) rather than a minimal fixed-size array.","Check `file <path>` reports ELF during install/CI sanity checks.","Point resolvers at the real ELF binary, not wrapper scripts or placeholders."],"tags":["elf","binary-parsing","file-io","java"],"backgroundTag":"file-read-failed","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"}