diff options
author | Ruben Ayrapetyan <ruben-ayrapetyan@users.noreply.github.com> | 2017-07-17 17:10:42 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2017-07-17 16:10:42 +0200 |
commit | 5ceac6362ffbc61b5159e4413d678a8ff6176f8b (patch) | |
tree | ad74300f376193b600faf551a55f0bddbc5dfea6 | |
parent | eef8181c9d4658f6ef5ac4705feb89aa85422186 (diff) | |
download | coreclr-5ceac6362ffbc61b5159e4413d678a8ff6176f8b.tar.gz coreclr-5ceac6362ffbc61b5159e4413d678a8ff6176f8b.tar.bz2 coreclr-5ceac6362ffbc61b5159e4413d678a8ff6176f8b.zip |
Fix alignment of reads in MD5Transform. (#12800)
-rw-r--r-- | src/utilcode/md5.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/utilcode/md5.cpp b/src/utilcode/md5.cpp index 8d6f8a3282..6901ddbf91 100644 --- a/src/utilcode/md5.cpp +++ b/src/utilcode/md5.cpp @@ -10,6 +10,7 @@ #include "stdafx.h" #include <stdlib.h> +#include "stdmacros.h" #include "md5.h" #include "contract.h" @@ -76,7 +77,16 @@ void MD5::HashMore(const void* pvInput, ULONG cbInput) // Hash the data in 64-byte runs, starting just after what we've copied while (cbInput >= 64) { - MD5Transform(m_state, (ULONG*)pbInput); + if (IS_ALIGNED(pbInput, sizeof(ULONG))) + { + MD5Transform(m_state, (ULONG*)pbInput); + } + else + { + ULONG inputCopy[64 / sizeof(ULONG)]; + memcpy(inputCopy, pbInput, sizeof(inputCopy)); + MD5Transform(m_state, inputCopy); + } pbInput += 64; cbInput -= 64; } @@ -213,6 +223,8 @@ void MD5::GetHashValue(MD5HASHDATA* phash) STATIC_CONTRACT_NOTHROW; STATIC_CONTRACT_GC_NOTRIGGER; + _ASSERTE(IS_ALIGNED(data, sizeof(ULONG))); + ULONG a=state[0]; ULONG b=state[1]; ULONG c=state[2]; |