{"record":{"id":"babe2d835121c20d","repo":"github/copilot-sdk","slug":"invalid-pt-interp-bounds","errorCode":null,"errorMessage":"Invalid PT_INTERP bounds","messagePattern":"Invalid PT_INTERP bounds","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java","lineNumber":231,"sourceCode":"            }\n\n            long pType = readUInt32(probe, base, littleEndian);\n            if (pType != PT_INTERP) {\n                continue;\n            }\n\n            long pOffset;\n            long pFileSize;\n            if (elfClass == ELF_CLASS_64) {\n                pOffset = readUInt64(probe, base + 8, littleEndian);\n                pFileSize = readUInt64(probe, base + 32, littleEndian);\n            } else {\n                pOffset = readUInt32(probe, base + 4, littleEndian);\n                pFileSize = readUInt32(probe, base + 16, littleEndian);\n            }\n\n            if (pOffset < 0 || pFileSize <= 0 || pOffset > Integer.MAX_VALUE || pFileSize > Integer.MAX_VALUE) {\n                throw new IOException(\"Invalid PT_INTERP bounds\");\n            }\n\n            int start = (int) pOffset;\n            int end = start + (int) pFileSize;\n            if (end > size) {\n                throw new IOException(\"PT_INTERP extends past probe window; increase probe size\");\n            }\n\n            int nulIndex = start;\n            while (nulIndex < end && probe[nulIndex] != 0) {\n                nulIndex++;\n            }\n            if (nulIndex == start) {\n                throw new IOException(\"Empty PT_INTERP segment\");\n            }\n            return new String(probe, start, nulIndex - start, StandardCharsets.UTF_8);\n        }\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/ffi/PlatformDetector.java#L213-L249","documentation":"When a PT_INTERP program header is found, its p_offset and p_filesz must be sane non-negative sizes within int range and describe a non-empty segment. Nonsensical values indicate a corrupt ELF, so an IOException is thrown rather than reading garbage as the interpreter path.","triggerScenarios":"A PT_INTERP entry whose p_offset is negative or > Integer.MAX_VALUE, or p_filesz <= 0 or > Integer.MAX_VALUE — corrupt program header fields or decoding from a misaligned/truncated probe.","commonSituations":"Corrupted binaries from partial downloads or bad patches; misaligned header reads because the probe didn't start at file offset 0 or the endianness/class assumptions were violated; fuzzed ELF inputs.","solutions":["Verify the binary with `readelf -l <path>`; if readelf shows a valid PT_INTERP, fix your probe/read logic (full-file or sufficiently large head read starting at offset 0).","Reinstall/re-download the binary and verify its checksum.","Ensure endianness and ELF class were detected correctly before decoding p_offset/p_filesz.","Treat as input rejection for untrusted files: catch IOException and report a corrupt-ELF message."],"exampleFix":"// before\nbyte[] probe = readHead(path, 512); // head slice may misalign p_offset decode\n// after\nbyte[] probe = Files.readAllBytes(path);\nString interp = readElfPtInterp(probe);","handlingStrategy":"try-catch","validationCode":"// Pre-verify with readelf output or ensure a full-file read so PT_INTERP bounds are real\nif (Files.size(path) > MAX_PROBE) throw new IOException(\"Unexpectedly large binary: \" + path);","typeGuard":null,"tryCatchPattern":"try {\n    String interp = readElfPtInterp(probe);\n} catch (IOException e) {\n    throw new IOException(\"PT_INTERP bounds invalid in \" + path + \" (\" + e.getMessage() + \"); file may be corrupt\", e);\n}","preventionTips":["Read the full file (or a large head slice from offset 0) before parsing program headers.","Detect ELF class and endianness before decoding p_offset/p_filesz.","Validate binary integrity with checksums.","Sanity-check parsed values with `readelf -l <path>` in CI."],"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"}