Skip to contentSkip to conversation

VMDK: probe for mono flat image

PATCH Superseded Fam Zheng 2 participants 6 messages Jun 4, 2011 – Jun 15, 2011 Block layer

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 3/12 VMDK: probe for mono flat image

vmdk_probe for mono flat images.

---
 block/vmdk.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
block/vmdk.c +0 -0
index f787528..bf8d02a 100644
@@ -101,10 +101,17 @@ static int vmdk_probe(const uint8_t *buf, int

buf_size, const char *filename)

         return 0;
     magic = be32_to_cpu(*(uint32_t *)buf);
     if (magic == VMDK3_MAGIC ||
-        magic == VMDK4_MAGIC)
+        magic == VMDK4_MAGIC) {
         return 100;
-    else
-        return 0;
+    } else {
+        char *cid_p, *ct_p, *extent_p;
+        cid_p = strstr((char *)buf, "CID");
+        ct_p = strstr((char *)buf, "createType");
+        extent_p = strstr((char *)buf, "RW");
+        if (cid_p && ct_p && extent_p)

+ return 100;
+ }
+ return 0;
}

#define CHECK_CID 1

#1 lore raw
Quoted 18 lines · Fam Zheng

vmdk_probe for mono flat images.

---
 block/vmdk.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
block/vmdk.c +1 -1
index f787528..bf8d02a 100644
@@ -101,10 +101,17 @@ static int vmdk_probe(const uint8_t *buf, int
 buf_size, const char *filename)
         return 0;
     magic = be32_to_cpu(*(uint32_t *)buf);
     if (magic == VMDK3_MAGIC ||
-        magic == VMDK4_MAGIC)
+        magic == VMDK4_MAGIC) {

block/vmdk.c static int vmdk_probe(const uint8_t *buf, int · line 113

Quoted 10 lines
block/vmdk.c +7 -2
         return 100;
-    else
-        return 0;
+    } else {
+        char *cid_p, *ct_p, *extent_p;
+        cid_p = strstr((char *)buf, "CID");
+        ct_p = strstr((char *)buf, "createType");
+        extent_p = strstr((char *)buf, "RW");
+        if (cid_p && ct_p && extent_p)
+            return 100;

NUL-terminated string functions cannot be used for probing because the input file may be invalid. If the magic number matches but there is no NUL in the buffer then the strstr(3) will run off the end of the buffer.

Also note that the specification says "The descriptor file is not case-sensitive". "cid", "CiD", and "CID" should all be allowed.

Do non-monolithic vmdk images always have "# Disk DescriptorFile" as the first line? Perhaps you can test for that using memcmp(3) instead.

Stefan

author
#2 lore raw
Quoted 34 lines · Stefan Hajnoczi
Quoted 20 lines · Fam Zheng

vmdk_probe for mono flat images.

---
 block/vmdk.c |   13 ++++++++++---

 1 files changed, 10 insertions(+), 3 deletions(-)
block/vmdk.c +0 -0
index f787528..bf8d02a 100644
@@ -101,10 +101,17 @@ static int vmdk_probe(const uint8_t *buf, int
 buf_size, const char *filename)
          return 0;
      magic = be32_to_cpu(*(uint32_t *)buf);

     if (magic == VMDK3_MAGIC ||
-        magic == VMDK4_MAGIC)
+        magic == VMDK4_MAGIC) {
         return 100;
-    else

Quoted 8 lines

-        return 0;
+    } else {
+        char *cid_p, *ct_p, *extent_p;
+        cid_p = strstr((char *)buf, "CID");
+        ct_p = strstr((char *)buf, "createType");
+        extent_p = strstr((char *)buf, "RW");
+        if (cid_p && ct_p && extent_p)
+            return 100;

NUL-terminated string functions cannot be used for probing because the input file may be invalid.  If the magic number matches but there is no NUL in the buffer then the strstr(3) will run off the end of the buffer.

Quoted 5 lines

Also note that the specification says "The descriptor file is not case-sensitive".  "cid", "CiD", and "CID" should all be allowed.

Do non-monolithic vmdk images always have "# Disk DescriptorFile" as the first line?  Perhaps you can test for that using memcmp(3) instead.

No guarantee in specification, although VMware does start descriptors with such a line "# Disk DescriptorFile".
But is it proper that we make this assumption?

Signature · 2 lines
Best regards!
Fam Zheng
#3 lore raw
Quoted 35 lines · Fam Zheng
Quoted 34 lines · Stefan Hajnoczi
Quoted 20 lines · Fam Zheng

vmdk_probe for mono flat images.

---
 block/vmdk.c |   13 ++++++++++---

 1 files changed, 10 insertions(+), 3 deletions(-)
block/vmdk.c +0 -0
index f787528..bf8d02a 100644
@@ -101,10 +101,17 @@ static int vmdk_probe(const uint8_t *buf, int
 buf_size, const char *filename)
          return 0;
      magic = be32_to_cpu(*(uint32_t *)buf);

     if (magic == VMDK3_MAGIC ||
-        magic == VMDK4_MAGIC)
+        magic == VMDK4_MAGIC) {
         return 100;
-    else

Quoted 8 lines

-        return 0;
+    } else {
+        char *cid_p, *ct_p, *extent_p;
+        cid_p = strstr((char *)buf, "CID");
+        ct_p = strstr((char *)buf, "createType");
+        extent_p = strstr((char *)buf, "RW");
+        if (cid_p && ct_p && extent_p)
+            return 100;

NUL-terminated string functions cannot be used for probing because the input file may be invalid.  If the magic number matches but there is no NUL in the buffer then the strstr(3) will run off the end of the buffer.

Quoted 8 lines
Quoted 5 lines

Also note that the specification says "The descriptor file is not case-sensitive".  "cid", "CiD", and "CID" should all be allowed.

Do non-monolithic vmdk images always have "# Disk DescriptorFile" as the first line?  Perhaps you can test for that using memcmp(3) instead.

No guarantee in specification, although VMware does start descriptors with such a line "# Disk DescriptorFile".
But is it proper that we make this assumption?

Have you tried removing that comment line to see if VMware still recognizes the file?

Stefan

author
#4 lore raw
Quoted 3 lines

Have you tried removing that comment line to see if VMware still recognizes the file?

Yes, it recognizes iff the first option line (non-comment, non-empty) is "version=1" or "version=2“.

(An interesting thing that it is both space sensitive and case sensitive)

Signature · 2 lines
Best regards!
Fam Zheng
#5 lore raw
Quoted 8 lines · Fam Zheng
Quoted 3 lines

Have you tried removing that comment line to see if VMware still recognizes the file?

Yes, it recognizes iff the first option line (non-comment, non-empty) is "version=1" or "version=2“.

(An interesting thing that it is both space sensitive and case sensitive)

Cool, nice job figuring this out. We should do the same.

Stefan