diff options
Diffstat (limited to 'block/dmg.c')
-rw-r--r-- | block/dmg.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/block/dmg.c b/block/dmg.c index b84ba7e690..dd8551cf27 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -450,6 +450,10 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } + if (ds.data_fork_offset > offset) { + ret = -EINVAL; + goto fail; + } /* offset of resource fork (RsrcForkOffset) */ ret = read_uint64(bs, offset + 0x28, &rsrc_fork_offset); @@ -460,6 +464,11 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } + if (rsrc_fork_offset >= offset || + rsrc_fork_length > offset - rsrc_fork_offset) { + ret = -EINVAL; + goto fail; + } /* offset of property list (XMLOffset) */ ret = read_uint64(bs, offset + 0xd8, &plist_xml_offset); if (ret < 0) { @@ -469,6 +478,11 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } + if (plist_xml_offset >= offset || + plist_xml_length > offset - plist_xml_offset) { + ret = -EINVAL; + goto fail; + } ret = read_uint64(bs, offset + 0x1ec, (uint64_t *)&bs->total_sectors); if (ret < 0) { goto fail; |