From a41bca3183351e84adc1694ba7643fe2656977c8 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Tue, 24 May 2016 11:48:10 +0100 Subject: [PATCH] [checksum] fix wrong checksums for content that isn't a multiple of 64 bytes * Leading odd-sized chunks needs to be tested *before* updating the bytecount * Closes #761 --- src/checksum.c | 56 ++++++++++++++++++++++---------------------------- src/rufus.rc | 10 ++++----- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/checksum.c b/src/checksum.c index 397c59c4..c9db99cb 100644 --- a/src/checksum.c +++ b/src/checksum.c @@ -453,26 +453,24 @@ static void md5_transform(SUM_CONTEXT *ctx, const unsigned char *data) /* Update the message digest with the contents of the buffer (SHA-1) */ static void sha1_write(SUM_CONTEXT *ctx, const unsigned char *buf, size_t len) { - size_t t; + size_t num = ctx->bytecount & 0x3f; /* Update bytecount */ ctx->bytecount += len; - t = ctx->bytecount & 0x3f; - /* Handle any leading odd-sized chunks */ - if (t) { - unsigned char *p = ctx->buf + t; + if (num) { + unsigned char *p = ctx->buf + num; - t = 64 - t; - if (len < t) { + num = 64 - num; + if (len < num) { memcpy(p, buf, len); return; } - memcpy(p, buf, t); + memcpy(p, buf, num); sha1_transform(ctx, ctx->buf); - buf += t; - len -= t; + buf += num; + len -= num; } /* Process data in 64-byte chunks */ @@ -490,26 +488,24 @@ static void sha1_write(SUM_CONTEXT *ctx, const unsigned char *buf, size_t len) /* Update the message digest with the contents of the buffer (SHA-256) */ static void sha256_write(SUM_CONTEXT *ctx, const unsigned char *buf, size_t len) { - size_t t; + size_t num = ctx->bytecount & 0x3f; /* Update bytecount */ ctx->bytecount += len; - t = ctx->bytecount & 0x3f; - /* Handle any leading odd-sized chunks */ - if (t) { - unsigned char *p = ctx->buf + t; + if (num) { + unsigned char *p = ctx->buf + num; - t = 64 - t; - if (len < t) { + num = 64 - num; + if (len < num) { memcpy(p, buf, len); return; } - memcpy(p, buf, t); + memcpy(p, buf, num); sha256_transform(ctx, ctx->buf); - buf += t; - len -= t; + buf += num; + len -= num; } /* Process data in 64-byte chunks */ @@ -527,26 +523,24 @@ static void sha256_write(SUM_CONTEXT *ctx, const unsigned char *buf, size_t len) /* Update the message digest with the contents of the buffer (MD5) */ static void md5_write(SUM_CONTEXT *ctx, const unsigned char *buf, size_t len) { - size_t t; + size_t num = ctx->bytecount & 0x3f; /* Update bytecount */ ctx->bytecount += len; - t = ctx->bytecount & 0x3f; - /* Handle any leading odd-sized chunks */ - if (t) { - unsigned char *p = ctx->buf + t; + if (num) { + unsigned char *p = ctx->buf + num; - t = 64 - t; - if (len < t) { - memcpy(p, buf, len); + num = 64 - num; + if (len < num) { + memcpy(p, buf, num); return; } - memcpy(p, buf, t); + memcpy(p, buf, num); md5_transform(ctx, ctx->buf); - buf += t; - len -= t; + buf += num; + len -= num; } /* Process data in 64-byte chunks */ diff --git a/src/rufus.rc b/src/rufus.rc index 172068a4..06151ebe 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 242, 376 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 2.10.937" +CAPTION "Rufus 2.10.938" FONT 8, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 @@ -320,8 +320,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,10,937,0 - PRODUCTVERSION 2,10,937,0 + FILEVERSION 2,10,938,0 + PRODUCTVERSION 2,10,938,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -338,13 +338,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "2.10.937" + VALUE "FileVersion", "2.10.938" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "2.10.937" + VALUE "ProductVersion", "2.10.938" END END BLOCK "VarFileInfo"