Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled error in pe_file.py #295

Open
mcutshaw opened this issue Dec 9, 2024 · 2 comments
Open

Unhandled error in pe_file.py #295

mcutshaw opened this issue Dec 9, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@mcutshaw
Copy link
Collaborator

mcutshaw commented Dec 9, 2024

Describe the bug
We are not handling the below error in pe_file.py, we will need to handle it or not run that extractor. I have additional information on the target file, contact me on Teams if needed.

To Reproduce
Steps to reproduce the behavior:

  1. Use unblob for extraction
  2. Generate config on directory
  3. Run generate on config
  4. See error
Traceback (most recent call last):
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/surfactant/cmd/generate.py", line 492, in sbom
    sw_parent, sw_children = get_software_entry(
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/surfactant/cmd/generate.py", line 58, in get_software_entry
    extracted_info_results: List[object] = pluginmanager.hook.extract_file_info(
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/surfactant/infoextractors/pe_file.py", line 31, in extract_file_info
    return extract_pe_info(filename)
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/surfactant/infoextractors/pe_file.py", line 135, in extract_pe_info
    com_desc_dir = opt_hdr_data_dir[com_desc_dir_num]
IndexError: list index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/mcutshaw/.local/bin/surfactant", line 8, in <module>
    sys.exit(main())
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/mcutshaw/.local/pipx/venvs/surfactant/lib/python3.10/site-packages/surfactant/cmd/generate.py", line 506, in sbom
    raise RuntimeError(f"Unable to process: {filepath}") from e
RuntimeError: Unable to process:

Expected behavior
Handle error and proceed.

System Information (please complete the following information):
Ubuntu 22.04
Installed with pipx
Python 3.10

Additional Information
The traceback is truncated intentionally.

@mcutshaw mcutshaw added the bug Something isn't working label Dec 9, 2024
@LLNL LLNL deleted a comment from CopilotTakeTheWheel Dec 10, 2024
@nightlark
Copy link
Collaborator

nightlark commented Dec 10, 2024

Teams doesn’t seem to be letting me send you a message (maybe it's being strange) - can you send me an email (or see if Teams will work for you)?

@nightlark
Copy link
Collaborator

From looking at the file that caused the crash, the underlying issue seems to be that the pefile library lists optional headers as being at "fixed" offsets in the list of data directories, but then omits entries that have an address/size of 0. I think this might even make some of the indices returned be invalid for directories that do exist. Also seems to relate to the issue discussed here: erocarrera/pefile#264

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants