* [Qemu-devel] [PATCH] Better .dmg autodetection
@ 2005-04-12 17:28 Alex Beregszaszi
2005-04-12 20:51 ` J. Mayer
0 siblings, 1 reply; 4+ messages in thread
From: Alex Beregszaszi @ 2005-04-12 17:28 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 804 bytes --]
Hi,
There are quiet lot fake dmg files floating around. These are just raw
images containing the Apple partition map and HFS partitions.
I hardened the autodetection of dmg files with more sanity checks. Real
dmg files are likely to be zlib compressed, and the header is placed at
the end. So the first sector of the file is used to be zlib data.
There are 3 parts of the detection:
* first look if the first byte means zlib data (CFM byte, compression
and format flags, the compression is ought to be 8, while the flags
should be less then 8), also if it validates, look if the filename ends
in .dmg
* check wether it is Apple partition map, the magic bytes are ER
* last check if the filename ends in .dmg
--
Alex Beregszaszi e-mail: alex@fsn.hu
Free Software Network cell: +36 70 3144424
[-- Attachment #2: block-dmg.detection.diff --]
[-- Type: text/x-diff, Size: 744 bytes --]
Index: block-dmg.c
===================================================================
RCS file: /cvsroot/qemu/qemu/block-dmg.c,v
retrieving revision 1.2
diff -u -r1.2 block-dmg.c
--- block-dmg.c 3 Jan 2005 23:39:08 -0000 1.2
+++ block-dmg.c 12 Apr 2005 17:25:09 -0000
@@ -52,6 +52,16 @@
static int dmg_probe(const uint8_t *buf, int buf_size, const char *filename)
{
int len=strlen(filename);
+
+ // Zlib CMF (4 bits CM, 4 bits flags)
+ if (((buf[0] & 0xf) == 8) && ((buf[0]&0xf0)<=7) &&
+ (len>4 && !strcmp(filename+len-4,".dmg")) )
+ return 50;
+
+ // Hopefully found Apple Partition map...
+ if ((buf[0] == 'E') && (buf[1] == 'R'))
+ return 0;
+
if(len>4 && !strcmp(filename+len-4,".dmg"))
return 2;
return 0;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] Better .dmg autodetection
2005-04-12 17:28 [Qemu-devel] [PATCH] Better .dmg autodetection Alex Beregszaszi
@ 2005-04-12 20:51 ` J. Mayer
2005-04-15 16:47 ` Alex Beregszaszi
0 siblings, 1 reply; 4+ messages in thread
From: J. Mayer @ 2005-04-12 20:51 UTC (permalink / raw)
To: qemu-devel
On Tue, 2005-04-12 at 19:28 +0200, Alex Beregszaszi wrote:
> Hi,
>
> There are quiet lot fake dmg files floating around. These are just raw
> images containing the Apple partition map and HFS partitions.
Those are not fake dmg.
With Apple disk utility, you are free to choose if the dmg is to be
compressed or not.
Then, uncompressed dmg are valid ones.
But, you don't need to manage them in block-dmg,c as those are just raw
images...
[...]
> * last check if the filename ends in .dmg
It seems to me that this check is not to be done.
There's no need to. If the first sector (after decompression, if needed)
is a valid Apple partition map _or_ a valid partition entry (ie with PM
magic at start), then it's a valid dmg. File extensions never mean
anything, they are just a user-interface oriented remainder, imho.
--
J. Mayer <l_indien@magic.fr>
Never organized
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] Better .dmg autodetection
2005-04-12 20:51 ` J. Mayer
@ 2005-04-15 16:47 ` Alex Beregszaszi
2005-04-15 23:41 ` J. Mayer
0 siblings, 1 reply; 4+ messages in thread
From: Alex Beregszaszi @ 2005-04-15 16:47 UTC (permalink / raw)
To: qemu-devel
Hi,
> > There are quiet lot fake dmg files floating around. These are just
> > raw images containing the Apple partition map and HFS partitions.
>
> Those are not fake dmg.
> With Apple disk utility, you are free to choose if the dmg is to be
> compressed or not.
> Then, uncompressed dmg are valid ones.
> But, you don't need to manage them in block-dmg,c as those are just
> raw images...
I spoke about better _autodetection_. Right now if it finds the .dmg
extension, the file will be threaten as DMG, and it will fail if I throw
an uncompressed one at it.
> > * last check if the filename ends in .dmg
>
> It seems to me that this check is not to be done.
> There's no need to. If the first sector (after decompression, if
> needed) is a valid Apple partition map _or_ a valid partition entry
> (ie with PM magic at start), then it's a valid dmg. File extensions
> never mean anything, they are just a user-interface oriented
> remainder, imho.
Dont forget that the current implementations relies only on the file
extension...
Wrong, if it starts with ER (disk header) or PM, it is definitely an
uncompressed file, thus it should be used via the raw interface. But if
the first bytes resemble the zlib compression, it is definitely a dmg
file which should be handled inside block-dmg.
--
Alex Beregszaszi e-mail: alex@fsn.hu
Free Software Network cell: +36 70 3144424
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] Better .dmg autodetection
2005-04-15 16:47 ` Alex Beregszaszi
@ 2005-04-15 23:41 ` J. Mayer
0 siblings, 0 replies; 4+ messages in thread
From: J. Mayer @ 2005-04-15 23:41 UTC (permalink / raw)
To: qemu-devel
On Fri, 2005-04-15 at 18:47 +0200, Alex Beregszaszi wrote:
> Hi,
>
> > > There are quiet lot fake dmg files floating around. These are just
> > > raw images containing the Apple partition map and HFS partitions.
> >
> > Those are not fake dmg.
> > With Apple disk utility, you are free to choose if the dmg is to be
> > compressed or not.
> > Then, uncompressed dmg are valid ones.
> > But, you don't need to manage them in block-dmg,c as those are just
> > raw images...
>
> I spoke about better _autodetection_. Right now if it finds the .dmg
> extension, the file will be threaten as DMG, and it will fail if I throw
> an uncompressed one at it.
OK, then I misunderstood you, there, sorry.
[...]
--
J. Mayer <l_indien@magic.fr>
Never organized
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-04-15 23:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-12 17:28 [Qemu-devel] [PATCH] Better .dmg autodetection Alex Beregszaszi
2005-04-12 20:51 ` J. Mayer
2005-04-15 16:47 ` Alex Beregszaszi
2005-04-15 23:41 ` J. Mayer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).