Pull request
Bug fixes for the .dmg image file format. -----BEGIN PGP SIGNATURE----- iQEcBAABAgAGBQJcL0GuAAoJEJykq7OBq3PIxvQH/31xbhtOqXFnKi8XTBfJP+d5 nYi7UFWkvtASPR9mNT3LnMfo4EPOHeumNhMJKiSA53uwwZMY4BBl+2L9btrTSCb2 LTyiMqGPpL35jl1bnZ+DSW3QbstTQe1eu8Dp/BrSAiVobCaBEnIBIEi9gWx0elyk npINaZ5tFsy0sXfL8g2MaPEkYN3xet0t/Uklx35ZQgTVT+SXzyuAs/7w1hTeG8vB Ve526A3hM1vy4SGGjRD8SaffC1uG25Gm0N1oSZlK8+QXnD4RYFpGVxEmwcWUcVKz qm+eDKsMwPrQmi7P89QJ3xxcLpcC40yhbh7szdIXHc7eNjgjHpBxnXxaFk3a8bw= =A3Qp -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging Pull request Bug fixes for the .dmg image file format. # gpg: Signature made Fri 04 Jan 2019 11:21:18 GMT # gpg: using RSA key 9CA4ABB381AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" # Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35 775A 9CA4 ABB3 81AB 73C8 * remotes/stefanha/tags/block-pull-request: dmg: don't skip zero chunk dmg: use enumeration type instead of hard coding number dmg: fix binary search dmg: Fixing wrong dmg block type value for block terminator. Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
6395fe0c2c
31
block/dmg.c
31
block/dmg.c
@ -54,7 +54,7 @@ enum {
|
|||||||
UDBZ,
|
UDBZ,
|
||||||
ULFO,
|
ULFO,
|
||||||
UDCM = 0x7ffffffe, /* Comments */
|
UDCM = 0x7ffffffe, /* Comments */
|
||||||
UDLE /* Last Entry */
|
UDLE = 0xffffffff /* Last Entry */
|
||||||
};
|
};
|
||||||
|
|
||||||
static int dmg_probe(const uint8_t *buf, int buf_size, const char *filename)
|
static int dmg_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
@ -130,7 +130,8 @@ static void update_max_chunk_size(BDRVDMGState *s, uint32_t chunk,
|
|||||||
case UDRW: /* copy */
|
case UDRW: /* copy */
|
||||||
uncompressed_sectors = DIV_ROUND_UP(s->lengths[chunk], 512);
|
uncompressed_sectors = DIV_ROUND_UP(s->lengths[chunk], 512);
|
||||||
break;
|
break;
|
||||||
case UDIG: /* zero */
|
case UDZE: /* zero */
|
||||||
|
case UDIG: /* ignore */
|
||||||
/* as the all-zeroes block may be large, it is treated specially: the
|
/* as the all-zeroes block may be large, it is treated specially: the
|
||||||
* sector is not copied from a large buffer, a simple memset is used
|
* sector is not copied from a large buffer, a simple memset is used
|
||||||
* instead. Therefore uncompressed_sectors does not need to be set. */
|
* instead. Therefore uncompressed_sectors does not need to be set. */
|
||||||
@ -199,8 +200,9 @@ typedef struct DmgHeaderState {
|
|||||||
static bool dmg_is_known_block_type(uint32_t entry_type)
|
static bool dmg_is_known_block_type(uint32_t entry_type)
|
||||||
{
|
{
|
||||||
switch (entry_type) {
|
switch (entry_type) {
|
||||||
|
case UDZE: /* zeros */
|
||||||
case UDRW: /* uncompressed */
|
case UDRW: /* uncompressed */
|
||||||
case UDIG: /* zeroes */
|
case UDIG: /* ignore */
|
||||||
case UDZO: /* zlib */
|
case UDZO: /* zlib */
|
||||||
return true;
|
return true;
|
||||||
case UDBZ: /* bzip2 */
|
case UDBZ: /* bzip2 */
|
||||||
@ -265,9 +267,10 @@ static int dmg_read_mish_block(BDRVDMGState *s, DmgHeaderState *ds,
|
|||||||
/* sector count */
|
/* sector count */
|
||||||
s->sectorcounts[i] = buff_read_uint64(buffer, offset + 0x10);
|
s->sectorcounts[i] = buff_read_uint64(buffer, offset + 0x10);
|
||||||
|
|
||||||
/* all-zeroes sector (type 2) does not need to be "uncompressed" and can
|
/* all-zeroes sector (type UDZE and UDIG) does not need to be
|
||||||
* therefore be unbounded. */
|
* "uncompressed" and can therefore be unbounded. */
|
||||||
if (s->types[i] != 2 && s->sectorcounts[i] > DMG_SECTORCOUNTS_MAX) {
|
if (s->types[i] != UDZE && s->types[i] != UDIG
|
||||||
|
&& s->sectorcounts[i] > DMG_SECTORCOUNTS_MAX) {
|
||||||
error_report("sector count %" PRIu64 " for chunk %" PRIu32
|
error_report("sector count %" PRIu64 " for chunk %" PRIu32
|
||||||
" is larger than max (%u)",
|
" is larger than max (%u)",
|
||||||
s->sectorcounts[i], i, DMG_SECTORCOUNTS_MAX);
|
s->sectorcounts[i], i, DMG_SECTORCOUNTS_MAX);
|
||||||
@ -572,16 +575,20 @@ static inline uint32_t search_chunk(BDRVDMGState *s, uint64_t sector_num)
|
|||||||
{
|
{
|
||||||
/* binary search */
|
/* binary search */
|
||||||
uint32_t chunk1 = 0, chunk2 = s->n_chunks, chunk3;
|
uint32_t chunk1 = 0, chunk2 = s->n_chunks, chunk3;
|
||||||
while (chunk1 != chunk2) {
|
while (chunk1 <= chunk2) {
|
||||||
chunk3 = (chunk1 + chunk2) / 2;
|
chunk3 = (chunk1 + chunk2) / 2;
|
||||||
if (s->sectors[chunk3] > sector_num) {
|
if (s->sectors[chunk3] > sector_num) {
|
||||||
chunk2 = chunk3;
|
if (chunk3 == 0) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
chunk2 = chunk3 - 1;
|
||||||
} else if (s->sectors[chunk3] + s->sectorcounts[chunk3] > sector_num) {
|
} else if (s->sectors[chunk3] + s->sectorcounts[chunk3] > sector_num) {
|
||||||
return chunk3;
|
return chunk3;
|
||||||
} else {
|
} else {
|
||||||
chunk1 = chunk3;
|
chunk1 = chunk3 + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
err:
|
||||||
return s->n_chunks; /* error */
|
return s->n_chunks; /* error */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,7 +678,8 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UDIG: /* zero */
|
case UDZE: /* zeros */
|
||||||
|
case UDIG: /* ignore */
|
||||||
/* see dmg_read, it is treated specially. No buffer needs to be
|
/* see dmg_read, it is treated specially. No buffer needs to be
|
||||||
* pre-filled, the zeroes can be set directly. */
|
* pre-filled, the zeroes can be set directly. */
|
||||||
break;
|
break;
|
||||||
@ -706,7 +714,8 @@ dmg_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
|
|||||||
/* Special case: current chunk is all zeroes. Do not perform a memcpy as
|
/* Special case: current chunk is all zeroes. Do not perform a memcpy as
|
||||||
* s->uncompressed_chunk may be too small to cover the large all-zeroes
|
* s->uncompressed_chunk may be too small to cover the large all-zeroes
|
||||||
* section. dmg_read_chunk is called to find s->current_chunk */
|
* section. dmg_read_chunk is called to find s->current_chunk */
|
||||||
if (s->types[s->current_chunk] == 2) { /* all zeroes block entry */
|
if (s->types[s->current_chunk] == UDZE
|
||||||
|
|| s->types[s->current_chunk] == UDIG) { /* all zeroes block entry */
|
||||||
qemu_iovec_memset(qiov, i * 512, 0, 512);
|
qemu_iovec_memset(qiov, i * 512, 0, 512);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user