Richard W.M. Jones
2011-Nov-22 08:54 UTC
[Libguestfs] [file PATCH] Properly detect .vdi (VirtualBox disk image) files
The current test for .vdi files is incorrect. It tries to detect the string "<<< Sun xVM VirtualBox Disk Image >>>". However this string is just free text and .vdi files often contain different strings (ref: [1]). The correct test in this patch looks for the magic number at offset 0x40 in the file (ref: [2]). Example: Upstream 'file' without the patch on an example file[3]: $ file ttylinux.vdi ttylinux.vdi: data With the patch: $ ./src/file -m magic/Magdir ttylinux.vdi ttylinux.vdi: VirtualBox Disk Image, major 1, minor 1 Rich. [1] http://repo.or.cz/w/qemu.git/blob/HEAD:/block/vdi.c#l109 [2] https://forums.virtualbox.org/viewtopic.php?t=8046 [3] https://one-vbox.googlecode.com/svn-history/r117/trunk/remotes/ttylinux.vdi -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org -------------- next part -------------- --- file-5.09.orig/magic/Magdir/virtual 2009-12-25 16:04:30.000000000 +0000 +++ file-5.09/magic/Magdir/virtual 2011-11-22 08:40:58.162840080 +0000 @@ -9,9 +9,9 @@ # .vhd 0 string conectix Microsoft Disk Image, Virtual Server or Virtual PC -# Sun xVM VirtualBox Disk Image -# string <<< Sun xVM VirtualBox Disk Image >>> +# From: Richard W.M. Jones <rich at annexia.org> +# VirtualBox Disk Image # .vdi -0 string \<\<\<\ Sun\ xVM\ VirtualBox\ Disk Sun xVM VirtualBox Disk Image - - +0x40 ulelong 0xbeda107f VirtualBox Disk Image +>0x44 uleshort >0 \b, major %u +>0x46 uleshort >0 \b, minor %u -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://listman.redhat.com/archives/libguestfs/attachments/20111122/d08c153f/attachment.sig>
Christos Zoulas
2011-Nov-22 13:30 UTC
[Libguestfs] [file PATCH] Properly detect .vdi (VirtualBox disk image) files
On Nov 22, 8:54am, rjones at redhat.com ("Richard W.M. Jones") wrote: -- Subject: [file PATCH] Properly detect .vdi (VirtualBox disk image) files | The current test for .vdi files is incorrect. It tries to detect the | string "<<< Sun xVM VirtualBox Disk Image >>>". However this string | is just free text and .vdi files often contain different strings (ref: [1]). | | The correct test in this patch looks for the magic number at offset | 0x40 in the file (ref: [2]). Fixed, thanks! christos