<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From b9370b63e1ba262320933a8d26c1dd9b3b2bc4b1 Mon Sep 17 00:00:00 2001
Message-Id: &lt;b9370b63e1ba262320933a8d26c1dd9b3b2bc4b1.1378302750.git.minovotn@redhat.com&gt;
From: Fam Zheng &lt;famz@redhat.com&gt;
Date: Tue, 27 Aug 2013 01:14:32 +0200
Subject: [PATCH 1/6] vmdk: Move l1_size check into vmdk_add_extent()

RH-Author: Fam Zheng &lt;famz@redhat.com&gt;
Message-id: &lt;1377566075-3289-2-git-send-email-famz@redhat.com&gt;
Patchwork-id: 53776
O-Subject: [RHEL-6.5 qemu-kvm PATCH 1/4] vmdk: Move l1_size check into vmdk_add_extent()
Bugzilla: 995865
RH-Acked-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
RH-Acked-by: Jeffrey Cody &lt;jcody@redhat.com&gt;
RH-Acked-by: Kevin Wolf &lt;kwolf@redhat.com&gt;

This header check is common to VMDK3 and VMDK4, so move it into
vmdk_add_extent().

Signed-off-by: Fam Zheng &lt;famz@redhat.com&gt;
Signed-off-by: Stefan Hajnoczi &lt;stefanha@redhat.com&gt;
(cherry picked from commit b0651b8c246d0d9e6ad0831b3e34fd756016ad7e)
Signed-off-by: Fam Zheng &lt;famz@redhat.com&gt;
---
 block/vmdk.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Signed-off-by: Michal Novotny &lt;minovotn@redhat.com&gt;
---
 block/vmdk.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index be9f1c5..30205f3 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -399,6 +399,14 @@ static int vmdk_add_extent(BlockDriverState *bs,
         error_report("invalid granularity, image may be corrupt");
         return -EINVAL;
     }
+    if (l1_size &gt; 512 * 1024 * 1024) {
+        /* Although with big capacity and small l1_entry_sectors, we can get a
+         * big l1_size, we don't want unbounded value to allocate the table.
+         * Limit it to 512M, which is 16PB for default cluster and L2 table
+         * size */
+        error_report("L1 size too big");
+        return -EFBIG;
+    }
 
     s-&gt;extents = g_realloc(s-&gt;extents,
                               (s-&gt;num_extents + 1) * sizeof(VmdkExtent));
@@ -596,14 +604,6 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
     }
     l1_size = (le64_to_cpu(header.capacity) + l1_entry_sectors - 1)
                 / l1_entry_sectors;
-    if (l1_size &gt; 512 * 1024 * 1024) {
-        /* although with big capacity and small l1_entry_sectors, we can get a
-         * big l1_size, we don't want unbounded value to allocate the table.
-         * Limit it to 512M, which is 16PB for default cluster and L2 table
-         * size */
-        error_report("L1 size too big");
-        return -EFBIG;
-    }
     if (le32_to_cpu(header.flags) &amp; VMDK4_FLAG_RGD) {
         l1_backup_offset = le64_to_cpu(header.rgd_offset) &lt;&lt; 9;
     }
-- 
1.7.11.7

</pre></body></html>