Closed valpogus closed 4 years ago
Interesting! I really don't know much about DLLs on Windows, but this caught my eye:
The default flags are set to only load DLL dependencies from trusted locations
Are there any locations that are trusted by default? If so, would it make sense to put the DLL there on your system?
Otherwise, if there are no "trusted locations" by default, maybe we should learn more about exactly what the security concerns are here. If just saying "search everywhere" or "use find_library" would undo the security this is meant to provide, maybe we need another option—such as an environment variable to indicate where the library is supposed to exist.
A quick search of my site-packages shows that many modules do use ctypes.util.find_library() (audioread, cffi, cairocffi, fdb, python-magic, send2trash...) and none uses winmode. I don't know about security, but find_library() seems to be at least the de facto standard.
Other libraries like pymediainfo ship the shared library inside the Windows wheel and then look for the library file in the installation directory.
Cool! It does seem like find_library
is pretty low on the concern scale. TBH I still don't quite understand what the "DLL hijacking" problem was with the old behavior, but find_library
seems reasonable enough?
Anyway, yes, that does seem like the right fix. Any chance you could open a PR?
OK, I'll do that
@sampsyo any plans to release the latest version on PyPi?
Yep! Soon.
The shared library 'libchromaprint.dll' is not found when using Python 3.8 on Windows even when the file is in a directory in the PATH. It is found when using Python 3.7 though.
The error possibly has to do with the way the DLL is loaded in chromaprint.py and the following change to ctypes in Python 3.8: https://docs.python.org/3/whatsnew/3.8.html#ctypes
I've thought about a couple of possible solutions, but I don't know, which one is right (if any)
https://docs.python.org/3/library/ctypes.html?highlight=winmode#ctypes.CDLL https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa
https://docs.python.org/3/library/ctypes.html?highlight=winmode#finding-shared-libraries