this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix unxip with some newer Xcode releases

+23 -7
+23 -7
src/unxip/xip_extract_cpio.c
··· 5 5 // Created by PHPdev32 on 6/20/14. 6 6 // Licensed under GPLv3, full text at http://www.gnu.org/licenses/gpl-3.0.txt 7 7 // 8 - // This code originated here: http://www.tonymacx86.com/threads/pbzx-stream-parser.135458/ 9 8 10 9 #include <stdio.h> 11 10 #include <stdint.h> 12 11 #include <string.h> 13 12 #include <stdlib.h> 14 13 #include <xar/xar.h> 15 - 14 + #include <lzma.h> 16 15 #define min(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) 17 16 #define err(c, m) if (c) { fprintf(stderr, m"\n"); exit(__COUNTER__ + 1); } 18 - #define XBSZ 1024*4 19 - #define ZBSZ 1024 17 + #define XBSZ 4 * 1024 18 + #define ZBSZ 1024 * XBSZ 20 19 21 20 static inline void xar_read(char *buffer, uint32_t size, xar_stream *stream) { 22 21 stream->next_out = buffer; ··· 58 57 xar_read(xbuf, 4, &xs); 59 58 err(strncmp(xbuf, "pbzx", 4), "Not a pbzx stream"); 60 59 uint64_t length = 0, flags = xar_read_64(&xs), last = 0; 60 + lzma_stream zs = LZMA_STREAM_INIT; 61 + err(lzma_stream_decoder(&zs, UINT64_MAX, LZMA_CONCATENATED) != LZMA_OK, "LZMA init failed"); 61 62 while (flags & 1 << 24) { 62 63 flags = xar_read_64(&xs); 63 64 length = xar_read_64(&xs); 64 - 65 + char plain = length == 0x1000000; 66 + xar_read(xbuf, min(XBSZ, (uint32_t)length), &xs); 67 + err(!plain && strncmp(xbuf, "\xfd""7zXZ\0", 6), "Header is not <FD>7zXZ<00>"); 65 68 while (length) { 69 + if (plain) 70 + cpio_out(xbuf, min(XBSZ, length)); 71 + else { 72 + zs.next_in = (typeof(zs.next_in))xbuf; 73 + zs.avail_in = min(XBSZ, length); 74 + while (zs.avail_in) { 75 + zs.next_out = (typeof(zs.next_out))zbuf; 76 + zs.avail_out = ZBSZ; 77 + err(lzma_code(&zs, LZMA_RUN) != LZMA_OK, "LZMA failure"); 78 + cpio_out(zbuf, ZBSZ - zs.avail_out); 79 + } 80 + } 81 + length -= last = min(XBSZ, length); 66 82 xar_read(xbuf, min(XBSZ, (uint32_t)length), &xs); 67 - cpio_out(xbuf, min(XBSZ, length)); 68 - length -= last = min(XBSZ, length); 69 83 } 84 + err(!plain && strncmp(xbuf + last - 2, "YZ", 2), "Footer is not YZ"); 70 85 } 71 86 xar_extract_tostream_end(&xs); 72 87 free(zbuf); 88 + lzma_end(&zs); 73 89 xar_close(x); 74 90 return 0; 75 91 }