- /* Read old and new backing file */
- ret = bdrv_read(bs_old_backing, sector, buf_old, n);
- if (ret < 0) {
- error_report("error while reading from old backing file");
- goto out;
+ /*
+ * Read old and new backing file and take into consideration that
+ * backing files may be smaller than the COW image.
+ */
+ if (sector >= old_backing_num_sectors) {
+ memset(buf_old, 0, n * BDRV_SECTOR_SIZE);
+ } else {
+ if (sector + n > old_backing_num_sectors) {
+ n = old_backing_num_sectors - sector;
+ }
+
+ ret = bdrv_read(bs_old_backing, sector, buf_old, n);
+ if (ret < 0) {
+ error_report("error while reading from old backing file");
+ goto out;
+ }