From b95e87040b8904b2d72c761de036ecceeb5be0a7 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 12 Oct 2017 16:40:54 +0100 Subject: [PATCH] [cmp] propagate decompression errors from bled If, for example, you have a truncated gz-compressed file and try to write it to disk, bled_uncompress_with_handles() will return an error. Previously, this was not reported back to the user -- there's no indication of any problem. If they're lucky, booting the partially-written disk will fail in an obvious way, but better to report an error sooner, even if we cannot give details. --- src/format.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/format.c b/src/format.c index 5d1e9353..76a30bee 100644 --- a/src/format.c +++ b/src/format.c @@ -1541,10 +1541,17 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, HANDLE hSourceImage) LastRefresh = 0; if (img_report.compression_type != BLED_COMPRESSION_NONE) { + int64_t bled_ret; uprintf("Writing Compressed Image..."); bled_init(_uprintf, update_progress, &FormatStatus); - bled_uncompress_with_handles(hSourceImage, hPhysicalDrive, img_report.compression_type); + bled_ret = bled_uncompress_with_handles(hSourceImage, hPhysicalDrive, img_report.compression_type); bled_exit(); + if (bled_ret < 0 && SCODE_CODE(FormatStatus) != ERROR_CANCELLED) { + // Unfortunately, different compression backends return different negative error codes + uprintf("Writing compressed image failed: %" PRIi64, bled_ret); + FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_WRITE_FAULT; + goto out; + } } else { uprintf(hSourceImage?"Writing Image...":"Zeroing drive..."); // Our buffer size must be a multiple of the sector size and *ALIGNED* to the sector size