Fix manifest HEAD response when looking up by label

Prior change Iaf6b83b61a470e8c5a61d18b7c241f9ca002c08a contained a bug
that and was returning an blank Content-Length for manifest HEAD
queries.  For this case, we have already read() the blob so we can
just return it's length for the HEAD query.

(the extant code was wrong for this case and self.storage.blob_size
was returning None, which got turned into 0 silently.  This leads to
the client reporting:

 failed commit on ref "manifest-sha256:ad38c...": unexpected commit digest
 sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855,
 expected  sha256:ad38c... failed precondition

I put this in for anyone googling who is seeing that e3b0c4... hash;
it's a clue that somehow you're trying to hash something empty.  This
slipped through because I tested pulling images, which worked, but it
fails when pulled in by docker build).

Change-Id: I7218843879ecd7939730060b6cee18af8190b888
This commit is contained in:
Ian Wienand 2021-09-17 16:28:13 +10:00
parent 43fb3fce3c
commit 6439b16c04

View File

@ -432,8 +432,7 @@ class RegistryAPI:
res.headers['Docker-Content-Digest'] = manifest[ct]
if method == 'HEAD':
# See comment above about head response
size = self.storage.blob_size(namespace, ref)
res.headers['Content-Length'] = size
res.headers['Content-Length'] = len(data)
return ''
return data
self.log.error('Manifest %s %s not found', repository, ref)