Skip to content

Commit

Permalink
building: validate binaries returned by analysis of ctypes calls
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rokm committed Oct 5, 2023
1 parent 73d2c0f commit 43f3d06
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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.

0 comments on commit 43f3d06

Please sign in to comment.