hdd_image: Don't return read error on out-of-bounds reads

This commit is contained in:
RichardG867
2024-11-03 11:22:27 -03:00
parent 26005b37b1
commit 558176e454
2 changed files with 3 additions and 3 deletions

View File

@@ -230,7 +230,7 @@ mvhd_fixed_read(MVHDMeta *vhdm, uint32_t offset, int num_sectors, void *out_buff
addr = ((int64_t) offset) * MVHD_SECTOR_SIZE;
if (mvhd_fseeko64(vhdm->f, addr, SEEK_SET) == -1)
vhdm->error = 1;
if (!fread(out_buff, transfer_sectors * MVHD_SECTOR_SIZE, 1, vhdm->f))
if (!fread(out_buff, transfer_sectors * MVHD_SECTOR_SIZE, 1, vhdm->f) && !feof(vhdm->f))
vhdm->error = 1;
return truncated_sectors;
@@ -272,7 +272,7 @@ mvhd_sparse_read(MVHDMeta *vhdm, uint32_t offset, int num_sectors, void *out_buf
}
if (VHD_TESTBIT(vhdm->bitmap.curr_bitmap, sib)) {
if (!fread(buff, MVHD_SECTOR_SIZE, 1, vhdm->f))
if (!fread(buff, MVHD_SECTOR_SIZE, 1, vhdm->f) && !feof(vhdm->f))
vhdm->error = 1;
} else {
memset(buff, 0, MVHD_SECTOR_SIZE);