From 408d9406a2c718c2840d7b47689cf0c1f92e8d38 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 31 2017 12:44:21 +0000 Subject: [PATCH 1/3] run checks earlier for cg_import Related: https://pagure.io/koji/issue/426 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index cbad388..178b483 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5633,6 +5633,14 @@ class CG_Importer(object): raise koji.GenericError('Output type %s not listed in build ' 'types' % btype) + if btype not in legacy_types: + raise koji.BuildError('unsupported archive type: %s' % type) + + if koji.CHECKSUM_TYPES[fileinfo['checksum_type']] != 'md5': + # XXX + # until we change the way we handle checksums, we have to limit this to md5 + raise koji.GenericError("Unsupported checksum type: %(checksum_type)s" % fileinfo) + fileinfo['hub.btype'] = btype fileinfo['hub.type_info'] = type_info From eecc9f4abad1e6e33a513ed426cbeba58d949e9b Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 31 2017 12:44:22 +0000 Subject: [PATCH 2/3] check all existing btypes --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 178b483..a9a925f 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5626,6 +5626,7 @@ class CG_Importer(object): btype = key type_info = extra['typeinfo'][key] + btype = lookup_name('btype', btype, strict=False) if btype is None: raise koji.GenericError("No typeinfo for: %(filename)s" % fileinfo) @@ -5633,9 +5634,6 @@ class CG_Importer(object): raise koji.GenericError('Output type %s not listed in build ' 'types' % btype) - if btype not in legacy_types: - raise koji.BuildError('unsupported archive type: %s' % type) - if koji.CHECKSUM_TYPES[fileinfo['checksum_type']] != 'md5': # XXX # until we change the way we handle checksums, we have to limit this to md5 From 0f393b1df14165a12d663f8c0c02611e70153887 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 31 2017 12:44:22 +0000 Subject: [PATCH 3/3] move checks earlier to prep_outputs --- diff --git a/hub/kojihub.py b/hub/kojihub.py index a9a925f..e174556 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5578,6 +5578,29 @@ class CG_Importer(object): workdir = koji.pathinfo.work() path = os.path.join(workdir, self.directory, fileinfo.get('relpath', ''), fileinfo['filename']) fileinfo['hub.path'] = path + + filesize = os.path.getsize(path) + if filesize != fileinfo['filesize']: + raise koji.GenericError("File size %s for %s (expected %s) doesn't match. Corrupted upload?" % + (filesize, fileinfo['filename'], fileinfo['filesize'])) + + # checksum + if koji.CHECKSUM_TYPES[fileinfo['checksum_type']] != 'md5': + # XXX + # until we change the way we handle checksums, we have to limit this to md5 + raise koji.GenericError("Unsupported checksum type: %(checksum_type)s" % fileinfo) + with open(path) as fp: + m = md5_constructor() + while True: + contents = fp.read(8192) + if not contents: + break + m.update(contents) + if fileinfo['checksum'] != m.hexdigest(): + raise koji.GenericError("File checksum mismatch for %s: %s != %s" % + (fileinfo['filename'], fileinfo['checksum'], m.hexdigest())) + fileinfo['hub.checked_md5'] = True + if fileinfo['buildroot_id'] not in self.br_prep: raise koji.GenericError("Missing buildroot metadata for id %(buildroot_id)r" % fileinfo) if fileinfo['type'] not in ['rpm', 'log']: @@ -5626,7 +5649,6 @@ class CG_Importer(object): btype = key type_info = extra['typeinfo'][key] - btype = lookup_name('btype', btype, strict=False) if btype is None: raise koji.GenericError("No typeinfo for: %(filename)s" % fileinfo) @@ -5634,11 +5656,6 @@ class CG_Importer(object): raise koji.GenericError('Output type %s not listed in build ' 'types' % btype) - if koji.CHECKSUM_TYPES[fileinfo['checksum_type']] != 'md5': - # XXX - # until we change the way we handle checksums, we have to limit this to md5 - raise koji.GenericError("Unsupported checksum type: %(checksum_type)s" % fileinfo) - fileinfo['hub.btype'] = btype fileinfo['hub.type_info'] = type_info @@ -6239,14 +6256,18 @@ def import_archive_internal(filepath, buildinfo, type, typeInfo, buildroot_id=No archiveinfo['filename'] = filename archiveinfo['size'] = os.path.getsize(filepath) archivefp = file(filepath) - m = md5_constructor() - while True: - contents = archivefp.read(8192) - if not contents: - break - m.update(contents) - archivefp.close() - archiveinfo['checksum'] = m.hexdigest() + # trust values computed on hub (CG_Importer.prep_outputs) + if not fileinfo or not getattr(fileinfo, 'hub.checked_md5'): + m = md5_constructor() + while True: + contents = archivefp.read(8192) + if not contents: + break + m.update(contents) + archivefp.close() + archiveinfo['checksum'] = m.hexdigest() + else: + archiveinfo['checksum'] = fileinfo['checksum'] archiveinfo['checksum_type'] = koji.CHECKSUM_TYPES['md5'] if fileinfo: # check against metadata