diff options
author | Stefan Bolte <sbolte@lavabit.com> | 2013-05-18 16:40:15 +0200 |
---|---|---|
committer | Stefan Bolte <sbolte@lavabit.com> | 2013-05-18 16:40:15 +0200 |
commit | 4cb8b48710ff693a03095a94fbaa15da546e2f27 (patch) | |
tree | 6938f8c7443c59bc116a7003abfef9fd0ba719de | |
parent | 258386a62ce8680025c8be355d8522e17d86fcc0 (diff) | |
download | dwb-4cb8b48710ff693a03095a94fbaa15da546e2f27.zip |
Unpack archives in 512 byte blocks
-rw-r--r-- | exar/exar.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/exar/exar.c b/exar/exar.c index 6748ed1c..94d92a71 100644 --- a/exar/exar.c +++ b/exar/exar.c @@ -379,10 +379,11 @@ exar_unpack(const char *archive, const char *dest) int ret = -1; char name[SZ_NAME], flag; - unsigned char rbuf; size_t fs; FILE *of, *f = NULL; int vers_check; + unsigned char buf[512]; + size_t r; f = open_archive(archive, "r", &vers_check, 1); if (f == NULL || vers_check == -1) @@ -420,10 +421,10 @@ exar_unpack(const char *archive, const char *dest) } LOG(2, "Writing %s (%lu bytes)\n", name, fs); - for (size_t i=0; i<fs; i++) + for (size_t i=0; i<fs; i += sizeof(buf)) { - if (fread(&rbuf, 1, 1, f) != 0) - fwrite(&rbuf, 1, 1, of); + if ( (r = fread(buf, 1, MIN(sizeof(buf), fs-i), f)) != 0) + fwrite(buf, 1, r, of); } LOG(3, "Closing %s\n", name); fclose(of); |