From 33bdae86c2345db9514addbf9d5a698eada56fb2 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Mon, 17 May 2021 12:57:54 +0200 Subject: Added alignment-aware block encryption/decryption --- src/SFileReadFile.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/SFileReadFile.cpp') diff --git a/src/SFileReadFile.cpp b/src/SFileReadFile.cpp index 34edc06..820f400 100644 --- a/src/SFileReadFile.cpp +++ b/src/SFileReadFile.cpp @@ -227,6 +227,9 @@ static DWORD ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFileP LPBYTE pbRawData; DWORD dwErrCode = ERROR_SUCCESS; + // The buffer needs to be aligned to 4-byte boundary + assert(STORMLIB_DWORD_ALIGNED(pbBuffer)); + // If the file buffer is not allocated yet, do it. if(hf->pbFileSector == NULL) { @@ -360,6 +363,7 @@ static DWORD ReadMpkFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFileP DWORD dwErrCode = ERROR_SUCCESS; // We do not support patch files in MPK archives + assert(STORMLIB_DWORD_ALIGNED(pvBuffer)); assert(hf->pPatchInfo == NULL); // If the file buffer is not allocated yet, do it. @@ -458,6 +462,9 @@ static DWORD ReadMpqFileSectorFile(TMPQFile * hf, void * pvBuffer, DWORD dwFileP DWORD dwBytesRead; // Number of bytes read (temporary variable) DWORD dwErrCode; + // The buffer needs to be aligned to 4-byte boundary + assert(STORMLIB_DWORD_ALIGNED(pbBuffer)); + // If the file position is at or beyond end of file, do nothing if(dwFilePos >= hf->dwDataSize) { @@ -576,6 +583,9 @@ static DWORD ReadMpqFilePatchFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePo DWORD dwBytesRead = 0; DWORD dwErrCode = ERROR_SUCCESS; + // Make sure that the buffer is properly aligned + assert(STORMLIB_DWORD_ALIGNED(pvBuffer)); + // Make sure that the patch file is loaded completely if(dwErrCode == ERROR_SUCCESS && hf->pbFileData == NULL) { -- cgit v1.2.3