From 02a500231ff77dd7f1eb2e35fb29ee2aff287658 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 2 Oct 2013 16:33:10 +0200 Subject: use dynamically allocated buffer when reading cached SHSH files --- src/idevicerestore.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/idevicerestore.c b/src/idevicerestore.c index 829b968..6b3e5d7 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -1316,8 +1316,29 @@ int get_shsh_blobs(struct idevicerestore_client_t* client, uint64_t ecid, unsign if (stat(zfn, &fst) == 0) { gzFile zf = gzopen(zfn, "rb"); if (zf) { - unsigned char bin[65536]; - int blen = gzread(zf, bin, sizeof(bin)); + int blen = 0; + int readsize = 16384; + int bufsize = readsize; + char* bin = (char*)malloc(bufsize); + char* p = bin; + do { + int bytes_read = gzread(zf, p, readsize); + if (bytes_read < 0) { + fprintf(stderr, "Error reading gz compressed data\n"); + exit(EXIT_FAILURE); + } + blen += bytes_read; + if (bytes_read < readsize) { + if (gzeof(zf)) { + bufsize += bytes_read; + break; + } + } + bufsize += readsize; + bin = realloc(bin, bufsize); + p = bin + blen; + } while (!gzeof(zf)); + gzclose(zf); if (blen > 0) { if (memcmp(bin, "bplist00", 8) == 0) { plist_from_bin(bin, blen, tss); @@ -1325,7 +1346,7 @@ int get_shsh_blobs(struct idevicerestore_client_t* client, uint64_t ecid, unsign plist_from_xml(bin, blen, tss); } } - gzclose(zf); + free(bin); } } else { error("no local file %s\n", zfn); -- cgit v1.1-32-gdbae