{"record":{"id":"009b609d48829d39","repo":"pypa/pip","slug":"unable-to-parse-machine-and-section-information","errorCode":null,"errorMessage":"unable to parse machine and section information","messagePattern":"unable to parse machine and section information","errorType":"validation","errorClass":"ELFInvalid","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/packaging/_elffile.py","lineNumber":88,"sourceCode":"            raise ELFInvalid(\n                f\"unrecognized capacity ({self.capacity}) or encoding ({self.encoding})\"\n            ) from e\n\n        try:\n            (\n                _,\n                self.machine,  # Architecture type.\n                _,\n                _,\n                self._e_phoff,  # Offset of program header.\n                _,\n                self.flags,  # Processor-specific flags.\n                _,\n                self._e_phentsize,  # Size of a program header entry.\n                self._e_phnum,  # Number of program headers.\n            ) = self._read(e_fmt)\n        except struct.error as e:\n            raise ELFInvalid(\"unable to parse machine and section information\") from e\n\n    def _read(self, fmt: str) -> tuple[int, ...]:\n        return struct.unpack(fmt, self._f.read(struct.calcsize(fmt)))\n\n    @property\n    def interpreter(self) -> str | None:\n        \"\"\"\n        The path recorded in the ``PT_INTERP`` section header.\n        \"\"\"\n        for index in range(self._e_phnum):\n            self._f.seek(self._e_phoff + self._e_phentsize * index)\n            try:\n                data = self._read(self._p_fmt)\n            except struct.error:\n                continue\n            if data[self._p_idx[0]] != 3:  # Not PT_INTERP.\n                continue\n            self._f.seek(data[self._p_idx[1]])","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/packaging/_elffile.py#L70-L106","documentation":"After validating identification bytes, ELFFile reads the main ELF header (type, machine, entry point, program header offset, flags, etc.) using a format string determined by class/encoding. If the file is truncated before the full header (52 bytes for 32-bit, 64 bytes for 64-bit after the 16-byte ident), struct.unpack raises struct.error, caught and re-raised as ELFInvalid.","triggerScenarios":"A truncated ELF file: valid magic and identification bytes but cut off before the complete ELF header can be read.","commonSituations":"Interrupted downloads, partial disk writes, corrupted archive extraction, or deliberately truncated test fixtures that start with a valid ELF magic but are incomplete.","solutions":["Check the file size meets the minimum for the detected class (at least 68 bytes for 32-bit, 80 bytes for 64-bit)","Re-download or re-extract the file from its source","Catch ELFInvalid and report the file as corrupted in batch processing"],"exampleFix":"# before\nelf = ELFFile(open(\"truncated_binary\", \"rb\"))  # raises\n\n# after\nimport os\nfile_size = os.path.getsize(\"truncated_binary\")\nif file_size < 80:\n    raise ValueError(f\"File is only {file_size} bytes, appears truncated\")\nelf = ELFFile(open(\"truncated_binary\", \"rb\"))","handlingStrategy":"try-catch","validationCode":"import os\n\ndef check_min_elf_size(path):\n    # 16-byte ident + 48-byte header minimum\n    if os.path.getsize(path) < 64:\n        raise ValueError(\"File too small for a complete ELF header\")","typeGuard":null,"tryCatchPattern":"from packaging._elffile import ELFFile, ELFInvalid\n\ntry:\n    elf = ELFFile(f)\nexcept ELFInvalid as e:\n    if \"unable to parse machine\" in str(e):\n        log.error(f\"Truncated ELF file: {path}\")","preventionTips":["Verify file integrity with checksums after download","Check file sizes against expected minimums","Handle truncated files explicitly in batch processing"],"tags":["elf","packaging","binary-parsing","corruption","vendored"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}