After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 797177 - Require tarball checksum verification for all recipes
Require tarball checksum verification for all recipes
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: cerbero
unspecified
Other All
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
: 773491 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2018-09-19 14:50 UTC by Nirbheek Chauhan
Modified: 2018-10-30 17:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
cerbero: Make FatalError exceptions more readable (2.41 KB, patch)
2018-09-19 14:50 UTC, Nirbheek Chauhan
committed Details | Review
cerbero: Use and require checksums for all tarball recipes (4.01 KB, patch)
2018-09-19 14:50 UTC, Nirbheek Chauhan
committed Details | Review
recipes: Add tarball checksums for all recipes (59.19 KB, patch)
2018-09-19 14:50 UTC, Nirbheek Chauhan
committed Details | Review

Description Nirbheek Chauhan 2018-09-19 14:50:33 UTC
The checksum is stored in the recipe and must be updated when a recipe is updated to a new version. This means we no longer need to rely on upstream download URLs for source tarballs to be trustworthy for eternity.
Comment 1 Nirbheek Chauhan 2018-09-19 14:50:40 UTC
Created attachment 373705 [details] [review]
cerbero: Make FatalError exceptions more readable

When the exception originates in a recipe, print the recipe path and the
line number with the error message. Otherwise, only print the error
message because that information is useless to the average cerbero user.

In any case, never print a traceback on FatalError
Comment 2 Nirbheek Chauhan 2018-09-19 14:50:46 UTC
Created attachment 373706 [details] [review]
cerbero: Use and require checksums for all tarball recipes

The sha256 checksum must be specified with the `tarball_checksum`
property on the recipe. If that property is not defined, a helpful
error message is printed.
Comment 3 Nirbheek Chauhan 2018-09-19 14:50:52 UTC
Created attachment 373707 [details] [review]
recipes: Add tarball checksums for all recipes

This should cover all recipes; even those that aren't built by default
Comment 4 Nicolas Dufresne (ndufresne) 2018-09-19 15:37:59 UTC
Review of attachment 373707 [details] [review]:

Could have been just name "checksum" instead of "tarball_checksum" ... haha, kidding, I don't really care. Note, I didn't recalculate all the checksum :-D
Comment 5 Nicolas Dufresne (ndufresne) 2018-09-19 15:40:31 UTC
Review of attachment 373705 [details] [review]:

Yeah, finally, thanks.
Comment 6 Nicolas Dufresne (ndufresne) 2018-09-19 15:45:59 UTC
Review of attachment 373706 [details] [review]:

::: cerbero/build/source.py
@@ +128,3 @@
         cached_file = os.path.join(self.config.cached_sources,
                                    self.package_name, self.tarball_name)
+        if not redownload and os.path.isfile(cached_file) and self.verify(cached_file, fatal=False):

I'm wondering if checking the cache won't be quite an overhead for the safety. What we could do instead is download to <filename>.unchecked, and if it succeed validate, move it back to it's real name. And then just trust the cache.

@@ +174,3 @@
+        if checksum != self.tarball_checksum:
+            movedto = fname + '.failed-checksum'
+            os.replace(fname, movedto)

I'm not familiar with replace, does it override if there is already a .failed-checksum file ? Just asking if we need to remove ancient failed download first.
Comment 7 Nirbheek Chauhan 2018-09-19 15:53:28 UTC
(In reply to Nicolas Dufresne (ndufresne) from comment #4)
> Review of attachment 373707 [details] [review] [review]:
> 
> Could have been just name "checksum" instead of "tarball_checksum" ... haha,
> kidding, I don't really care. Note, I didn't recalculate all the checksum :-D


Just to entertain the bikeshed for a moment, I thought `tarball_checksum` would be good alongside `tarball_dirname` and `tarball_name`. :)

(In reply to Nicolas Dufresne (ndufresne) from comment #6)
> Review of attachment 373706 [details] [review] [review]:
> 
> ::: cerbero/build/source.py
> @@ +128,3 @@
>          cached_file = os.path.join(self.config.cached_sources,
>                                     self.package_name, self.tarball_name)
> +        if not redownload and os.path.isfile(cached_file) and
> self.verify(cached_file, fatal=False):
> 
> I'm wondering if checking the cache won't be quite an overhead for the
> safety. What we could do instead is download to <filename>.unchecked, and if
> it succeed validate, move it back to it's real name. And then just trust the
> cache.
> 

It's actually not a lot of overhead at all. It takes <2 seconds to verify all the tarball checksums in gstreamer-1.0, which is a trivial amount of time compared to building stuff. I tested with: 

time ./cerbero-uninstalled fetch-package gstreamer-1.0

So I think it's good to keep the implementation simple. It's also a good way to know and recover easily if a file in your cache got corrupted somehow.

> @@ +174,3 @@
> +        if checksum != self.tarball_checksum:
> +            movedto = fname + '.failed-checksum'
> +            os.replace(fname, movedto)
> 
> I'm not familiar with replace, does it override if there is already a
> .failed-checksum file ? Just asking if we need to remove ancient failed
> download first.

Yes, os.replace is a cross-platform API to overwrite the existing file: https://docs.python.org/3/library/os.html#os.replace
Comment 8 Nicolas Dufresne (ndufresne) 2018-09-19 16:35:40 UTC
Review of attachment 373706 [details] [review]:

Ok, sounds good.
Comment 9 Nirbheek Chauhan 2018-09-20 08:45:38 UTC
Thanks for the review!

Attachment 373705 [details] pushed as 2f2ec83 - cerbero: Make FatalError exceptions more readable
Attachment 373706 [details] pushed as bdc074c - cerbero: Use and require checksums for all tarball recipes
Attachment 373707 [details] pushed as 7949284 - recipes: Add tarball checksums for all recipes
Comment 10 Nirbheek Chauhan 2018-10-30 17:58:02 UTC
*** Bug 773491 has been marked as a duplicate of this bug. ***