diff --git a/data/registry_model/blobuploader.py b/data/registry_model/blobuploader.py index a356f78e6..478a3d9af 100644 --- a/data/registry_model/blobuploader.py +++ b/data/registry_model/blobuploader.py @@ -24,6 +24,9 @@ BLOB_CONTENT_TYPE = 'application/octet-stream' class BlobUploadException(Exception): """ Base for all exceptions raised when uploading blobs. """ +class BlobRangeMismatchException(BlobUploadException): + """ Exception raised if the range to be uploaded does not match. """ + class BlobDigestMismatchException(BlobUploadException): """ Exception raised if the digest requested does not match that of the contents uploaded. """ @@ -134,7 +137,7 @@ class _BlobUploadManager(object): if start_offset > 0 and start_offset > self.blob_upload.byte_count: logger.error('start_offset provided greater than blob_upload.byte_count') - raise BlobUploadException() + raise BlobRangeMismatchException() # Ensure that we won't go over the allowed maximum size for blobs. max_blob_size = bitmath.parse_string_unsafe(self.settings.maximum_blob_size) diff --git a/endpoints/v2/blob.py b/endpoints/v2/blob.py index 73ffc553f..0bfbe7b52 100644 --- a/endpoints/v2/blob.py +++ b/endpoints/v2/blob.py @@ -10,7 +10,8 @@ from data import database from data.registry_model import registry_model from data.registry_model.blobuploader import (create_blob_upload, retrieve_blob_upload_manager, complete_when_uploaded, BlobUploadSettings, - BlobUploadException, BlobTooLargeException) + BlobUploadException, BlobTooLargeException, + BlobRangeMismatchException) from digest import digest_tools from endpoints.decorators import anon_protect, parse_repository_name from endpoints.v2 import v2_bp, require_repo_read, require_repo_write, get_input_stream @@ -428,7 +429,10 @@ def _upload_chunk(blob_uploader, commit_digest=None): return blob_uploader.commit_to_blob(app.config, commit_digest) except BlobTooLargeException as ble: raise LayerTooLarge(uploaded=ble.uploaded, max_allowed=ble.max_allowed) - except BlobUploadException: + except BlobRangeMismatchException: logger.exception('Exception when uploading blob to %s', blob_uploader.blob_upload_id) _abort_range_not_satisfiable(blob_uploader.blob_upload.byte_count, blob_uploader.blob_upload_id) + except BlobUploadException: + logger.exception('Exception when uploading blob to %s', blob_uploader.blob_upload_id) + raise BlobUploadInvalid()