mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 07:55:21 +01:00
gz/xz/zstd custom images: pad if image size is not dividable by 512 bytes
Disk image sizes that are not dividable by 512 bytes should not exist, as that is the minimum sector size any disk can have, and the smallest unit an OS can write to a disk. We were already rejecting such image files if we know in advance the size was wrong, which we can test if they are uncompressed, if they are in an easy parsable file format such as .zip, or if the repository meta data indicated the uncompressed size. However for gz/xz/zstd files this check is not done, and it would fail at the verification stage instead. If encountering such corner case, pad the image instead of failing. Ref #364
This commit is contained in:
parent
0a07169a8a
commit
c00a451f6c
1 changed files with 8 additions and 0 deletions
|
@ -151,6 +151,14 @@ void DownloadExtractThread::extractImageRun()
|
||||||
throw runtime_error(archive_error_string(a));
|
throw runtime_error(archive_error_string(a));
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
break;
|
break;
|
||||||
|
if (size % 512 != 0)
|
||||||
|
{
|
||||||
|
size_t paddingBytes = 512-(size % 512);
|
||||||
|
qDebug() << "Image is NOT a valid disk image, as its length is not a multiple of the sector size of 512 bytes long";
|
||||||
|
qDebug() << "Last write() would be" << size << "bytes, but padding to" << size + paddingBytes << "bytes";
|
||||||
|
memset(_abuf[_activeBuf]+size, 0, paddingBytes);
|
||||||
|
size += paddingBytes;
|
||||||
|
}
|
||||||
|
|
||||||
if (_writeThreadStarted)
|
if (_writeThreadStarted)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue