From 127a101b141635f0ffd3c16709975a59a24e32b8 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Wed, 13 Apr 2011 14:50:26 +1000 Subject: [PATCH] Disable md5 checking on apple for now till someone fixes it. --- lrzip.c | 7 +++++-- lrzip_private.h | 6 ++++++ rzip.c | 34 ++++++++++++++++++++-------------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/lrzip.c b/lrzip.c index dce63af..8070d8f 100644 --- a/lrzip.c +++ b/lrzip.c @@ -101,7 +101,8 @@ void write_magic(rzip_control *control) * which can be used as an integrity check instead of crc check. * crc is still stored for compatibility with 0.5 versions. */ - magic[21] = 1; + if (!NO_MD5) + magic[21] = 1; if (ENCRYPT) magic[22] = 1; @@ -155,7 +156,7 @@ static void get_magic(rzip_control *control, char *magic) /* Whether this archive contains md5 data at the end or not */ md5 = magic[21]; - if (md5) { + if (md5 && MD5_RELIABLE) { if (md5 == 1) control->flags |= FLAG_MD5; else @@ -961,6 +962,8 @@ void compress_file(rzip_control *control) int fd_in, fd_out = -1; char header[MAGIC_LEN]; + if (MD5_RELIABLE) + control->flags |= FLAG_MD5; if (ENCRYPT) get_hash(control, 1); memset(header, 0, sizeof(header)); diff --git a/lrzip_private.h b/lrzip_private.h index 492f3f8..fda47d2 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -95,6 +95,12 @@ typedef struct md5_ctx md5_ctx; #define mremap fake_mremap #endif +#if defined(__APPLE__) +# define MD5_RELIABLE (0) +#else +# define MD5_RELIABLE (1) +#endif + #define bswap_32(x) \ ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) diff --git a/rzip.c b/rzip.c index abbc8fe..cb88297 100644 --- a/rzip.c +++ b/rzip.c @@ -624,7 +624,8 @@ static void hash_search(rzip_control *control, struct rzip_state *st, double pct for (i = 0; i < n; i++) memcpy(ckbuf + i, get_sb(control, cksum_limit + i), 1); st->cksum = CrcUpdate(st->cksum, ckbuf, n); - md5_process_bytes(ckbuf, n, &control->ctx); + if (!NO_MD5) + md5_process_bytes(ckbuf, n, &control->ctx); cksum_limit += n; free(ckbuf); } @@ -645,7 +646,8 @@ static void hash_search(rzip_control *control, struct rzip_state *st, double pct for (i = 0; i < n; i++) memcpy(ckbuf + i, get_sb(control, cksum_limit + i), 1); st->cksum = CrcUpdate(st->cksum, ckbuf, n); - md5_process_bytes(ckbuf, n, &control->ctx); + if (!NO_MD5) + md5_process_bytes(ckbuf, n, &control->ctx); cksum_limit += n; free(ckbuf); } @@ -773,7 +775,8 @@ void rzip_fd(rzip_control *control, int fd_in, int fd_out) double chunkmbs; i64 free_space; - md5_init_ctx (&control->ctx); + if (!NO_MD5) + md5_init_ctx (&control->ctx); st = calloc(sizeof(*st), 1); if (unlikely(!st)) @@ -975,18 +978,21 @@ retry: if (likely(st->hash_table)) free(st->hash_table); - md5_finish_ctx(&control->ctx, md5_resblock); - if (HASH_CHECK || MAX_VERBOSE) { - print_output("MD5: "); - for (j = 0; j < MD5_DIGEST_SIZE; j++) - print_output("%02x", md5_resblock[j] & 0xFF); - print_output("\n"); + if (!NO_MD5) { + /* Temporary workaround till someone fixes apple md5 */ + md5_finish_ctx(&control->ctx, md5_resblock); + if (HASH_CHECK || MAX_VERBOSE) { + print_output("MD5: "); + for (j = 0; j < MD5_DIGEST_SIZE; j++) + print_output("%02x", md5_resblock[j] & 0xFF); + print_output("\n"); + } + /* When encrypting data, we encrypt the MD5 value as well */ + if (ENCRYPT) + lrz_encrypt(control, md5_resblock, MD5_DIGEST_SIZE, control->salt_pass); + if (unlikely(write_1g(control, md5_resblock, MD5_DIGEST_SIZE) != MD5_DIGEST_SIZE)) + fatal("Failed to write md5 in rzip_fd\n"); } - /* When encrypting data, we encrypt the MD5 value as well */ - if (ENCRYPT) - lrz_encrypt(control, md5_resblock, MD5_DIGEST_SIZE, control->salt_pass); - if (unlikely(write_1g(control, md5_resblock, MD5_DIGEST_SIZE) != MD5_DIGEST_SIZE)) - fatal("Failed to write md5 in rzip_fd\n"); if (TMP_OUTBUF) flush_tmpoutbuf(control);