On 9/17/19 12:07 PM, Vladimir Sementsov-Ogievskiy wrote:
We shouldn't try to copy bytes beyond EOF. Fix it.
Fixes: 9ded4a0114968e
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com>
Reviewed-by: Max Reitz <mre...@redhat.com>
---
block/backup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/backup.c b/block/backup.c
index d8fdbfadfe..89f7f89200 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -161,7 +161,7 @@ static int coroutine_fn
backup_cow_with_offload(BackupBlockJob *job,
assert(QEMU_IS_ALIGNED(job->copy_range_size, job->cluster_size));
assert(QEMU_IS_ALIGNED(start, job->cluster_size));
- nbytes = MIN(job->copy_range_size, end - start);
+ nbytes = MIN(job->copy_range_size, MIN(end, job->len) - start);
I'm a little confused. I think the patch as written is correct, but I
don't know what problem it solves.
If we're going to allow the caller to pass in an end that's beyond EOF,
does that mean we are *requiring* the caller to pass in a value that's
aligned?
We should probably assert what kind of a value we're accepted here,
right? We do for start, but should we for 'end' as well?
Then ...
nr_clusters = DIV_ROUND_UP(nbytes, job->cluster_size);
Don't we just round this right back up immediately anyway? Does that
mean we have callers that are passing in an 'end' that's more than 1
job-cluster beyond EOF? That seems like something that should be fixed
in the caller, surely?
bdrv_reset_dirty_bitmap(job->copy_bitmap, start,
job->cluster_size * nr_clusters);