VMDK: probe for mono flat image
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
@@ -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
Quoted 18 lines · Fam Zheng
vmdk_probefor mono flat images.Signed-off-by Fam Zheng <[email protected]>--- block/vmdk.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)block/vmdk.c +1
-1@@ -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
-2return 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
Quoted 34 lines · Stefan Hajnoczi
Quoted 20 lines · Fam Zheng
vmdk_probefor mono flat images.Signed-off-by Fam Zheng <[email protected]>---
block/vmdk.c | 13 ++++++++++---1 files changed, 10 insertions(+), 3 deletions(-)block/vmdk.c +0
-0@@ -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;
- elseQuoted 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
Quoted 35 lines · Fam Zheng
Quoted 34 lines · Stefan Hajnoczi
Quoted 20 lines · Fam Zheng
vmdk_probefor mono flat images.Signed-off-by Fam Zheng <[email protected]>---
block/vmdk.c | 13 ++++++++++---1 files changed, 10 insertions(+), 3 deletions(-)block/vmdk.c +0
-0@@ -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;
- elseQuoted 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
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
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