@@ -1492,7 +1492,7 @@ async def _downloadPackage(self, packageStep, depth, packageBuildId):
14921492 dissectPackageInputState (BobState ().getInputHashes (prettyPackagePath ))
14931493 workspaceChanged = False
14941494 wasDownloaded = False
1495- audit = os .path .join (prettyPackagePath , ".." , "audit.json.gz" )
1495+ audit = os .path .normpath ( os . path . join (prettyPackagePath , ".." , "audit.json.gz" ) )
14961496 packageDigest = packageStep .getVariantId ()
14971497
14981498 # prune directory if we previously downloaded/built something different
@@ -1509,6 +1509,7 @@ async def _downloadPackage(self, packageStep, depth, packageBuildId):
15091509 stepMessage (packageStep , "PRUNE" , "{} ({})" .format (prettyPackagePath ,
15101510 reason ), WARNING )
15111511 emptyDirectory (prettyPackagePath )
1512+ removePath (audit )
15121513 BobState ().resetWorkspaceState (prettyPackagePath , packageDigest )
15131514 oldInputBuildId = None
15141515 oldInputFingerprint = None
@@ -1522,9 +1523,19 @@ async def _downloadPackage(self, packageStep, depth, packageBuildId):
15221523 packageBuildId , audit , prettyPackagePath , executor = self .__executor )
15231524 if wasDownloaded :
15241525 self .__statistic .packagesDownloaded += 1
1526+ # Reject downloads without audit trail. They cannot be verified
1527+ # and break the audit trail of downstream packages.
1528+ if not os .path .exists (audit ):
1529+ raise BuildError ("Downloaded artifact misses its audit trail!" )
1530+
1531+ # Verify integrity of downloaded package to protect against
1532+ # data corruption.
1533+ packageHash = hashWorkspace (packageStep )
1534+ if Audit .fromFile (audit ).getArtifact ().getResultHash () != packageHash :
1535+ raise BuildError ("Corrupt downloaded artifact! Extracted content hash does not match audit trail." )
1536+
15251537 BobState ().setInputHashes (prettyPackagePath ,
15261538 packageInputDownloaded (packageBuildId ))
1527- packageHash = hashWorkspace (packageStep )
15281539 workspaceChanged = True
15291540 elif layerDownloadMode == 'forced' :
15301541 raise BuildError ("Downloading artifact of layer %s failed" % layer )
0 commit comments