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

building: validate binaries returned by analysis of ctypes calls #7984

Merged
merged 1 commit into from Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions PyInstaller/building/build_main.py
Expand Up @@ -661,10 +661,17 @@ def assemble(self):

for name, co in ctypes_code_objs.items():
# Get dlls that might be needed by ctypes.
logger.debug('Scanning %s for shared libraries or dlls', name)
logger.debug('Scanning %s for ctypes-based references to shared libraries', name)
try:
ctypes_binaries = scan_code_for_ctypes(co)
self.binaries.extend(set(ctypes_binaries))
# As this scan happens after automatic binary-vs-data classification, we need to validate the binaries
# ourselves, just in case.
for dest_name, src_name, typecode in set(ctypes_binaries):
# Allow for `None` in case re-classification is not supported on the given platform.
if bindepend.classify_binary_vs_data(src_name) not in (None, 'BINARY'):
logger.warning("Ignoring %s found via ctypes - not a valid binary!", src_name)
continue
self.binaries.append((dest_name, src_name, typecode))
except Exception as ex:
raise RuntimeError(f"Failed to scan the module '{name}'. This is a bug. Please report it.") from ex

Expand Down
6 changes: 6 additions & 0 deletions news/7984.bugfix.rst
@@ -0,0 +1,6 @@
Validate binaries returned by analysis of ``ctypes`` calls in collected
modules; the analysis might return files that are in ``PATH`` but are
not binaries, which then cause errors during binary dependency analysis.
An example of such problematic case is the ``gmsh`` package on Windows,
where ``ctypes.util.find_library('gmsh')`` ends up resolving the python
script called ``gmsh`` in the environment's Scripts directory.