summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2013-10-02 16:33:10 +0200
committerGravatar Nikias Bassen2013-10-02 16:33:10 +0200
commit02a500231ff77dd7f1eb2e35fb29ee2aff287658 (patch)
treeef44e667154dde38ab8f2a3bd2e6cdf3fd8e27e2
parent930031521ab8abc4423cb00360074aa801db2d1e (diff)
downloadidevicerestore-02a500231ff77dd7f1eb2e35fb29ee2aff287658.tar.gz
idevicerestore-02a500231ff77dd7f1eb2e35fb29ee2aff287658.tar.bz2
use dynamically allocated buffer when reading cached SHSH files
-rw-r--r--src/idevicerestore.c27
1 files 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);