-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Shouldn't pip fail installing modified wheel file? (checking hash against RECORD) #2752
Comments
The
However, installers are tot required by the PEP to do these checks, and indeed pip currently does neither check. I don't think there's any problem in principle with adding such checks, it's just not been done. They are of limited value in practice, of course, because anyone with access to the files to modify them also has access to the One possible issue with including hash checks is that for a large wheel (think something like scipy at over 85MB for Christoph Gohlke's Windows wheels) calculating hashes for every file would take a non-trivial amount of time. Basically, not enough value to justify the cost of adding the checks. |
I see, thank you very much for clear and detailed answer. |
The specification does require hash checks on install. I know we didn't use the word MUST in all caps. It doesn't take very long to compute SHA256. https://www.python.org/dev/peps/pep-0427/#the-dist-info-directory "During extraction, wheel installers verify all the hashes in RECORD against the file contents. Apart from RECORD and its signatures, installation will fail if any file in the archive is not both mentioned and correctly hashed in RECORD. " |
Patches would be welcome, obviously :-) Personally, I'd like to see a benchmark against an 80MB+ wheel as well, but I could probably run that test for myself if a PR was submitted. As a data point, it looks to me as if pip and "wheel install" don't check hashes on install but distlib does. The fact that distlib does is empirical evidence that the overhead of checking isn't an issue. (I'm still not 100% sure precisely what damage it's intended to protect against, though - after all, it appears that the OP was trying to do something that the check would have prevented unless he updated the hashes, so in that case the check would actually have made his life harder). |
For the record, sha256 can get well over 100 MiB/s. I don't believe it provides any meaning full protection against any attack. It may have another purpose
|
It is designed this way so that you can sign RECORD to verify the integrity of the archive and include the signature inside the wheel file so that it travels with the archive and is much more likely to be available when you install, similar to jar files. wheel install itself does check the hashes by using a ZipFile subclass. https://bitbucket.org/pypa/wheel/src/tip/wheel/install.py?at=default#cl-413 |
Ah. I thought it only did that for signed wheels. It never occurred to me that |
Thanks for further explanations. Just to clarify my initial intentions: I wasn't trying to do anything But after I saw this actually works, it made me wonder why it did... And if So the bottom line for me is: if I edit wheel file directly, I should
|
We should build a simple tool to zip up a directory while updating the RECORD |
... or |
wheel unpack is already there. we would just have to add the pack command or even 'update record' in which case you could zip it yourself. |
On Fri, May 8, 2015 at 10:51 PM, Daniel Holth [email protected]
|
Any updates from this thread? We recently hit an issue for reorganizing the packed wheel and rezipping wheel isn't the best way to do it. See tensorflow/tensorflow#29561 for context. |
Hi @byronyi. The The general issue of checking hashes on installation is also tracked by #4705. I'll close this issue in favor of that one since it is a bit more focused. |
Hello,
I've noticed that unpacking wheel, making some edits in its files and zipping everything right back without updating the RECORD file, doesn't result on any warnings or errors from pip.
Reading PEP 0427 it's not clear to me if the hash records in dist-info/RECORD should always be verified or only when wheel is signed. In case it's the second option, sorry for the noise :-)
Small example just in case:
The text was updated successfully, but these errors were encountered: