@@ -330,14 +330,16 @@ int qcow2_snapshot_goto(BlockDriverState *bs,
const char *snapshot_id)
if (qcow2_grow_l1_table(bs, sn->l1_size, true) < 0)
goto fail;
- s->l1_size = sn->l1_size;
- l1_size2 = s->l1_size * sizeof(uint64_t);
+ if (s->l1_size > sn->l1_size) {
+ memset(s->l1_table + sn->l1_size, 0, (s->l1_size -
sn->l1_size) * sizeof(uint64_t));
+ }
+ l1_size2 = sn->l1_size * sizeof(uint64_t);
/* copy the snapshot l1 table to the current l1 table */
if (bdrv_pread(bs->file, sn->l1_table_offset,
s->l1_table, l1_size2) != l1_size2)
goto fail;
if (bdrv_pwrite_sync(bs->file, s->l1_table_offset,
- s->l1_table, l1_size2) < 0)
+ s->l1_table, s->l1_size * sizeof(uint64_t)) < 0)
goto fail;