From f67ca8b616fa955f9f1de3cfda31de3d208600d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Thu, 11 Feb 2021 14:19:12 +0100 Subject: [PATCH] azure: return an early error if unaligned MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the image size isn't aligned to 512 bytes, the Azure API returns very hard to understand error message. Let's do this check ourselves early so we can return a sane error. Signed-off-by: Ondřej Budai --- internal/upload/azure/azure.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/upload/azure/azure.go b/internal/upload/azure/azure.go index 42bbca8d4..cd3e4aa6e 100644 --- a/internal/upload/azure/azure.go +++ b/internal/upload/azure/azure.go @@ -71,6 +71,10 @@ func UploadImage(credentials Credentials, metadata ImageMetadata, fileName strin return fmt.Errorf("cannot stat the image: %v", err) } + if stat.Size()%512 != 0 { + return errors.New("size for azure image must be aligned to 512 bytes") + } + // Hash the imageFile imageFileHash := md5.New() if _, err := io.Copy(imageFileHash, imageFile); err != nil {