[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 03/10] block/dmg: extract processing of resource for
From: |
Peter Wu |
Subject: |
[Qemu-devel] [PATCH 03/10] block/dmg: extract processing of resource forks |
Date: |
Sat, 27 Dec 2014 16:01:37 +0100 |
Besides the offset, also read the resource length. This length is now
used in the extracted function to verify the end of the resource fork
against "count" from the resource fork.
Signed-off-by: Peter Wu <address@hidden>
---
block/dmg.c | 90 ++++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 59 insertions(+), 31 deletions(-)
diff --git a/block/dmg.c b/block/dmg.c
index 6dc6dbb..7f49388 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -278,38 +278,13 @@ fail:
return ret;
}
-static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
- Error **errp)
+static int dmg_read_resource_fork(BlockDriverState *bs, DmgHeaderState *ds,
+ uint64_t info_begin, uint64_t info_length)
{
- BDRVDMGState *s = bs->opaque;
- DmgHeaderState ds;
- uint64_t info_begin, info_end;
- uint32_t count, tmp;
- int64_t offset;
int ret;
-
- bs->read_only = 1;
- s->n_chunks = 0;
- s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL;
- ds.last_in_offset = 0;
- ds.last_out_offset = 0;
- ds.max_compressed_size = 1;
- ds.max_sectors_per_chunk = 1;
-
- /* locate the UDIF trailer */
- offset = dmg_find_koly_offset(bs->file);
- if (offset < 0) {
- ret = offset;
- goto fail;
- }
-
- ret = read_uint64(bs, offset + 0x28, &info_begin);
- if (ret < 0) {
- goto fail;
- } else if (info_begin == 0) {
- ret = -EINVAL;
- goto fail;
- }
+ uint32_t count, tmp;
+ uint64_t info_end;
+ uint64_t offset;
ret = read_uint32(bs, info_begin, &tmp);
if (ret < 0) {
@@ -326,6 +301,10 @@ static int dmg_open(BlockDriverState *bs, QDict *options,
int flags,
ret = -EINVAL;
goto fail;
}
+ if (count > info_length) {
+ ret = -EINVAL;
+ goto fail;
+ }
info_end = info_begin + count;
/* begin of mish block */
@@ -342,12 +321,61 @@ static int dmg_open(BlockDriverState *bs, QDict *options,
int flags,
}
offset += 4;
- ret = dmg_read_mish_block(bs, &ds, offset, count);
+ ret = dmg_read_mish_block(bs, ds, offset, count);
if (ret < 0) {
goto fail;
}
offset += count;
}
+ return 0;
+
+fail:
+ return ret;
+}
+
+static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
+ Error **errp)
+{
+ BDRVDMGState *s = bs->opaque;
+ DmgHeaderState ds;
+ uint64_t rsrc_fork_offset, rsrc_fork_length;
+ int64_t offset;
+ int ret;
+
+ bs->read_only = 1;
+ s->n_chunks = 0;
+ s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL;
+ ds.last_in_offset = 0;
+ ds.last_out_offset = 0;
+ ds.max_compressed_size = 1;
+ ds.max_sectors_per_chunk = 1;
+
+ /* locate the UDIF trailer */
+ offset = dmg_find_koly_offset(bs->file);
+ if (offset < 0) {
+ ret = offset;
+ goto fail;
+ }
+
+ /* offset of resource fork (RsrcForkOffset) */
+ ret = read_uint64(bs, offset + 0x28, &rsrc_fork_offset);
+ if (ret < 0) {
+ goto fail;
+ }
+ ret = read_uint64(bs, offset + 0x30, &rsrc_fork_length);
+ if (ret < 0) {
+ goto fail;
+ }
+ if (rsrc_fork_offset != 0 && rsrc_fork_length != 0) {
+ ret = dmg_read_resource_fork(bs, &ds,
+ rsrc_fork_offset, rsrc_fork_length);
+ if (ret < 0) {
+ goto fail;
+ }
+ } else {
+ ret = -EINVAL;
+ goto fail;
+ }
/* initialize zlib engine */
s->compressed_chunk = qemu_try_blockalign(bs->file,
--
2.2.1
- [Qemu-devel] [PATCH 00/10] block/dmg: (compatibility) fixes and bzip2 support, Peter Wu, 2014/12/27
- [Qemu-devel] [PATCH 05/10] block/dmg: validate chunk size to avoid overflow, Peter Wu, 2014/12/27
- [Qemu-devel] [PATCH 01/10] block/dmg: properly detect the UDIF trailer, Peter Wu, 2014/12/27
- [Qemu-devel] [PATCH 08/10] block/dmg: fix sector data offset calculation, Peter Wu, 2014/12/27
- [Qemu-devel] [PATCH 06/10] block/dmg: process XML plists, Peter Wu, 2014/12/27
- [Qemu-devel] [PATCH 07/10] block/dmg: set virtual size to a non-zero value, Peter Wu, 2014/12/27
- [Qemu-devel] [PATCH 04/10] block/dmg: process a buffer instead of reading ints, Peter Wu, 2014/12/27
- [Qemu-devel] [PATCH 02/10] block/dmg: extract mish block decoding functionality, Peter Wu, 2014/12/27
- [Qemu-devel] [PATCH 09/10] block/dmg: support bzip2 block entry types, Peter Wu, 2014/12/27
- [Qemu-devel] [PATCH 03/10] block/dmg: extract processing of resource forks,
Peter Wu <=
- [Qemu-devel] [PATCH 10/10] block/dmg: improve zeroes handling, Peter Wu, 2014/12/27