{"record":{"id":"85f6c0ef2aa5b133","repo":"github/copilot-sdk","slug":"invalid-elf-program-header-metadata-phentsize","errorCode":null,"errorMessage":"Invalid ELF program header metadata: phentsize= + phentsize + , phnum= + phnum","messagePattern":"Invalid ELF program header metadata: phentsize= \\+ phentsize \\+ , phnum= \\+ phnum","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java","lineNumber":202,"sourceCode":"        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            }\n\n            long pType = readUInt32(probe, base, littleEndian);\n            if (pType != PT_INTERP) {\n                continue;\n            }\n\n            long pOffset;","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java#L184-L220","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nbyte[] probe = readHead(path, 128); // too small for many phdrs\nString interp = readElfPtInterp(probe);\n// after\nlong fileSize = Files.size(path);\nbyte[] probe = readHead(path, (int) Math.min(fileSize, 65536));\nString interp = readElfPtInterp(probe);","handlingStrategy":"validation","validationCode":"// phentsize >= 56 (ELF64) or 32 (ELF32) and phnum > 0 for a valid table\n// ensure probe.length >= phoff + phentsize * phnum before parsing","typeGuard":null,"tryCatchPattern":"try {\n    String interp = readElfPtInterp(probe);\n} catch (IOException e) {\n    throw new IOException(\"Corrupt or truncated ELF (\" + e.getMessage() + \"); verify the binary\", e);\n}","preventionTips":["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."],"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"}