-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
tools/mpremote: For mip install, use hash to skip files that exist. #17205
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
tools/mpremote: For mip install, use hash to skip files that exist. #17205
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #17205 +/- ##
=======================================
Coverage 98.54% 98.54%
=======================================
Files 169 169
Lines 21890 21890
=======================================
Hits 21572 21572
Misses 318 318 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code size report:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is comparing the short hash, which is 8 hex characters (32 bits), is that right?
I think this is OK, we can expect a 50% chance of a collision in a single source file after 65,536 iterations (cribbed from here, I didn't check their working but it sounds about right to me). Individual files won't have anywhere close to that many versions uploaded to the package archive, so that's probably OK.
(That's accidental collisions, if an attacker wanted to produce a source file with a short hash collision then this would be relatively easy. However, I can't think what the benefit to an attacker would be - the only use I can think of would be to put the generated source file on the device and ensure it wasn't replaced by the one from the package, but that doesn't seem particularly valuable.)
This hash is a fundamental piece of the mip design, and mip will stop working if there are any collisions. See the comment here: https://github.com/micropython/micropython-lib/blob/master/tools/build.py#L89-L95 So, if there's ever a collision we need to increase the hash length. |
When using `mip install`, if a file that needs to be downloaded already exists locally, then the hash of that local file will be computed and if it matches the known hash of the remote file it will not be downloaded. Hashes in mip are guaranteed unique, so this change should never leave stale files on the filesystem. This behaviour follows that of the `mip` package in `micropython-lib`. Signed-off-by: Damien George <damien@micropython.org>
3cc05f4
to
e53f262
Compare
Summary
When using
mip install
, if a file that needs to be downloaded already exists locally, then the hash of that local file will be computed and if it matches the known hash of the remote file it will not be downloaded.This behaviour follows that of the
mip
package inmicropython-lib
.Testing
Tested on RPI_PICO2_W. Prior to this change, with
unittest
already installed:With this change:
Trade-offs and Alternatives
Hashes in
mip
are guaranteed unique, so this change should never leave stale files on the filesystem.