dmg.c (32cc71def9e3885f9527af713e6d8dc7521ddc08) | dmg.c (353a5d84b25c335b259f37c4f43dad96e6d60ba8) |
---|---|
1/* 2 * QEMU Block driver for DMG images 3 * 4 * Copyright (c) 2004 Johannes E. Schindelin 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 376 unchanged lines hidden (view full) --- 385 if (info_length == 0 || info_length > 16 * 1024 * 1024) { 386 ret = -EINVAL; 387 goto fail; 388 } 389 390 buffer = g_malloc(info_length + 1); 391 buffer[info_length] = '\0'; 392 ret = bdrv_pread(bs->file, info_begin, info_length, buffer, 0); | 1/* 2 * QEMU Block driver for DMG images 3 * 4 * Copyright (c) 2004 Johannes E. Schindelin 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 376 unchanged lines hidden (view full) --- 385 if (info_length == 0 || info_length > 16 * 1024 * 1024) { 386 ret = -EINVAL; 387 goto fail; 388 } 389 390 buffer = g_malloc(info_length + 1); 391 buffer[info_length] = '\0'; 392 ret = bdrv_pread(bs->file, info_begin, info_length, buffer, 0); |
393 if (ret != info_length) { | 393 if (ret < 0) { |
394 ret = -EINVAL; 395 goto fail; 396 } 397 398 /* look for <data>...</data>. The data is 284 (0x11c) bytes after base64 399 * decode. The actual data element has 431 (0x1af) bytes which includes tabs 400 * and line feeds. */ 401 data_end = (char *)buffer; --- 204 unchanged lines hidden (view full) --- 606 607 s->current_chunk = s->n_chunks; 608 switch (s->types[chunk]) { /* block entry type */ 609 case UDZO: { /* zlib compressed */ 610 /* we need to buffer, because only the chunk as whole can be 611 * inflated. */ 612 ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], 613 s->compressed_chunk, 0); | 394 ret = -EINVAL; 395 goto fail; 396 } 397 398 /* look for <data>...</data>. The data is 284 (0x11c) bytes after base64 399 * decode. The actual data element has 431 (0x1af) bytes which includes tabs 400 * and line feeds. */ 401 data_end = (char *)buffer; --- 204 unchanged lines hidden (view full) --- 606 607 s->current_chunk = s->n_chunks; 608 switch (s->types[chunk]) { /* block entry type */ 609 case UDZO: { /* zlib compressed */ 610 /* we need to buffer, because only the chunk as whole can be 611 * inflated. */ 612 ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], 613 s->compressed_chunk, 0); |
614 if (ret != s->lengths[chunk]) { | 614 if (ret < 0) { |
615 return -1; 616 } 617 618 s->zstream.next_in = s->compressed_chunk; 619 s->zstream.avail_in = s->lengths[chunk]; 620 s->zstream.next_out = s->uncompressed_chunk; 621 s->zstream.avail_out = 512 * s->sectorcounts[chunk]; 622 ret = inflateReset(&s->zstream); --- 9 unchanged lines hidden (view full) --- 632 case UDBZ: /* bzip2 compressed */ 633 if (!dmg_uncompress_bz2) { 634 break; 635 } 636 /* we need to buffer, because only the chunk as whole can be 637 * inflated. */ 638 ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], 639 s->compressed_chunk, 0); | 615 return -1; 616 } 617 618 s->zstream.next_in = s->compressed_chunk; 619 s->zstream.avail_in = s->lengths[chunk]; 620 s->zstream.next_out = s->uncompressed_chunk; 621 s->zstream.avail_out = 512 * s->sectorcounts[chunk]; 622 ret = inflateReset(&s->zstream); --- 9 unchanged lines hidden (view full) --- 632 case UDBZ: /* bzip2 compressed */ 633 if (!dmg_uncompress_bz2) { 634 break; 635 } 636 /* we need to buffer, because only the chunk as whole can be 637 * inflated. */ 638 ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], 639 s->compressed_chunk, 0); |
640 if (ret != s->lengths[chunk]) { | 640 if (ret < 0) { |
641 return -1; 642 } 643 644 ret = dmg_uncompress_bz2((char *)s->compressed_chunk, 645 (unsigned int) s->lengths[chunk], 646 (char *)s->uncompressed_chunk, 647 (unsigned int) 648 (512 * s->sectorcounts[chunk])); --- 4 unchanged lines hidden (view full) --- 653 case ULFO: 654 if (!dmg_uncompress_lzfse) { 655 break; 656 } 657 /* we need to buffer, because only the chunk as whole can be 658 * inflated. */ 659 ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], 660 s->compressed_chunk, 0); | 641 return -1; 642 } 643 644 ret = dmg_uncompress_bz2((char *)s->compressed_chunk, 645 (unsigned int) s->lengths[chunk], 646 (char *)s->uncompressed_chunk, 647 (unsigned int) 648 (512 * s->sectorcounts[chunk])); --- 4 unchanged lines hidden (view full) --- 653 case ULFO: 654 if (!dmg_uncompress_lzfse) { 655 break; 656 } 657 /* we need to buffer, because only the chunk as whole can be 658 * inflated. */ 659 ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], 660 s->compressed_chunk, 0); |
661 if (ret != s->lengths[chunk]) { | 661 if (ret < 0) { |
662 return -1; 663 } 664 665 ret = dmg_uncompress_lzfse((char *)s->compressed_chunk, 666 (unsigned int) s->lengths[chunk], 667 (char *)s->uncompressed_chunk, 668 (unsigned int) 669 (512 * s->sectorcounts[chunk])); 670 if (ret < 0) { 671 return ret; 672 } 673 break; 674 case UDRW: /* copy */ 675 ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], 676 s->uncompressed_chunk, 0); | 662 return -1; 663 } 664 665 ret = dmg_uncompress_lzfse((char *)s->compressed_chunk, 666 (unsigned int) s->lengths[chunk], 667 (char *)s->uncompressed_chunk, 668 (unsigned int) 669 (512 * s->sectorcounts[chunk])); 670 if (ret < 0) { 671 return ret; 672 } 673 break; 674 case UDRW: /* copy */ 675 ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], 676 s->uncompressed_chunk, 0); |
677 if (ret != s->lengths[chunk]) { | 677 if (ret < 0) { |
678 return -1; 679 } 680 break; 681 case UDZE: /* zeros */ 682 case UDIG: /* ignore */ 683 /* see dmg_read, it is treated specially. No buffer needs to be 684 * pre-filled, the zeroes can be set directly. */ 685 break; --- 80 unchanged lines hidden --- | 678 return -1; 679 } 680 break; 681 case UDZE: /* zeros */ 682 case UDIG: /* ignore */ 683 /* see dmg_read, it is treated specially. No buffer needs to be 684 * pre-filled, the zeroes can be set directly. */ 685 break; --- 80 unchanged lines hidden --- |