diff --git a/PyInstaller/building/build_main.py b/PyInstaller/building/build_main.py index 1862148596..bc2e35e87a 100644 --- a/PyInstaller/building/build_main.py +++ b/PyInstaller/building/build_main.py @@ -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 diff --git a/news/7984.bugfix.rst b/news/7984.bugfix.rst new file mode 100644 index 0000000000..4d3ea9e6b6 --- /dev/null +++ b/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.