diff --git a/src/disk/hdd_image.c b/src/disk/hdd_image.c index 402140408..c702d9f29 100644 --- a/src/disk/hdd_image.c +++ b/src/disk/hdd_image.c @@ -542,7 +542,7 @@ hdd_image_read(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer) num_read = fread(buffer, 512, count, hdd_images[id].file); hdd_images[id].pos = sector + num_read; - if (num_read < count) + if ((num_read < count) && !feof(hdd_images[id].file)) return -1; } diff --git a/src/disk/minivhd/minivhd_io.c b/src/disk/minivhd/minivhd_io.c index cdf6694a8..3b75ca74d 100644 --- a/src/disk/minivhd/minivhd_io.c +++ b/src/disk/minivhd/minivhd_io.c @@ -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);