Revision d191d12d block/qcow2.c

b/block/qcow2.c
166 166

  
167 167
    if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION)
168 168
        goto fail;
169
    if (header.size <= 1 ||
170
        header.cluster_bits < MIN_CLUSTER_BITS ||
169
    if (header.cluster_bits < MIN_CLUSTER_BITS ||
171 170
        header.cluster_bits > MAX_CLUSTER_BITS)
172 171
        goto fail;
173 172
    if (header.crypt_method > QCOW_CRYPT_AES)
......
200 199
    if (s->l1_size < s->l1_vm_state_index)
201 200
        goto fail;
202 201
    s->l1_table_offset = header.l1_table_offset;
203
    s->l1_table = qemu_mallocz(
204
        align_offset(s->l1_size * sizeof(uint64_t), 512));
205
    if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
206
        s->l1_size * sizeof(uint64_t))
207
        goto fail;
208
    for(i = 0;i < s->l1_size; i++) {
209
        be64_to_cpus(&s->l1_table[i]);
202
    if (s->l1_size > 0) {
203
        s->l1_table = qemu_mallocz(
204
            align_offset(s->l1_size * sizeof(uint64_t), 512));
205
        if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
206
            s->l1_size * sizeof(uint64_t))
207
            goto fail;
208
        for(i = 0;i < s->l1_size; i++) {
209
            be64_to_cpus(&s->l1_table[i]);
210
        }
210 211
    }
211 212
    /* alloc L2 cache */
212 213
    s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));

Also available in: Unified diff