def __init__(self, *, path: str) -> None: """Initialize an ElfFile instance. :param str path: path to an elf_file within a snapcraft project. """ self.path = path self.dependencies = set() # type: Set[Library] self.arch: Optional[ElfArchitectureTuple] = None self.interp: str = "" self.soname: str = "" self.versions: Set[str] = set() self.needed: Dict[str, NeededLibrary] = dict() self.execstack_set: bool = False self.is_dynamic: bool = True self.build_id: str = "" self.has_debug_info: bool = False # String of elf enum type, e.g. "ET_DYN", "ET_EXEC", etc. self.elf_type: str = "ET_NONE" try: logger.debug(f"Extracting ELF attributes: {path}") self._extract_attributes() except (UnicodeDecodeError, AttributeError, ConstructError) as exception: logger.debug( f"Extracting ELF attributes exception: {str(exception)}") raise errors.CorruptedElfFileError(path, exception)
def __init__(self, *, path: str) -> None: """Initialize an ElfFile instance. :param str path: path to an elf_file within a snapcraft project. """ self.path = path self.dependencies = set() # type: Set[Library] try: elf_data = self._extract(path) except (UnicodeDecodeError, AttributeError) as exception: raise errors.CorruptedElfFileError(path, exception) self.arch = elf_data[0] self.interp = elf_data[1] self.soname = elf_data[2] self.needed = elf_data[3] self.execstack_set = elf_data[4] self.is_dynamic = elf_data[5]
def __init__(self, *, path: str) -> None: """Initialize an ElfFile instance. :param str path: path to an elf_file within a snapcraft project. """ self.path = path self.dependencies = set() # type: Set[Library] self.arch: Optional[ElfArchitectureTuple] = None self.interp: str = "" self.soname: str = "" self.needed: Dict[str, NeededLibrary] = dict() self.execstack_set: bool = False self.is_dynamic: bool = True self.build_id: str = "" self.has_debug_info: bool = False try: self._extract_attributes() except (UnicodeDecodeError, AttributeError) as exception: raise errors.CorruptedElfFileError(path, exception)
def test_is_valid_elf_ignores_corrupt_files(self): soname = "libssl.so.1.0.0" soname_path = os.path.join(self.path, soname) library = elf.Library( soname=soname, soname_path=soname_path, search_paths=[self.path], core_base_path="/snap/core/current", arch=("ELFCLASS64", "ELFDATA2LSB", "EM_X86_64"), soname_cache=elf.SonameCache(), ) self.assertThat(library._is_valid_elf(soname_path), Equals(True)) self.useFixture( fixtures.MockPatch( "snapcraft.internal.elf.ElfFile", side_effect=errors.CorruptedElfFileError(path=soname_path, error=RuntimeError()), )) self.assertThat(library._is_valid_elf(soname_path), Equals(False))