aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLadislav Zezula <zezula@volny.cz>2023-02-07 09:10:58 +0100
committerGitHub <noreply@github.com>2023-02-07 09:10:58 +0100
commit33e6a2bdfec872c31bfd7ce2899012c129894f7e (patch)
tree6cebd387986b6870d03161d1bc25d9c1c382651d /src
parent9beaed54cd6ef17ba3e0209233a29bd74184de6f (diff)
parent01e940f998e64ceb60d39a30d0e40c33be430744 (diff)
Merge pull request #285 from ladislav-zezula/LZ_LzmaFix
Fixed bug in the LZMA compression
Diffstat (limited to 'src')
-rw-r--r--src/SCompression.cpp2
-rw-r--r--src/SFileAddFile.cpp10
-rw-r--r--src/SFileCreateArchive.cpp9
3 files changed, 18 insertions, 3 deletions
diff --git a/src/SCompression.cpp b/src/SCompression.cpp
index 54c84b4..659c9a8 100644
--- a/src/SCompression.cpp
+++ b/src/SCompression.cpp
@@ -461,7 +461,7 @@ static void Compress_LZMA(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuf
*pbOutBuffer++ = 0;
// Copy the encoded properties to the output buffer
- memcpy(pvOutBuffer, encodedProps, encodedPropsSize);
+ memcpy(pbOutBuffer, encodedProps, encodedPropsSize);
pbOutBuffer += encodedPropsSize;
// Copy the size of the data
diff --git a/src/SFileAddFile.cpp b/src/SFileAddFile.cpp
index b1288f1..5913424 100644
--- a/src/SFileAddFile.cpp
+++ b/src/SFileAddFile.cpp
@@ -896,6 +896,7 @@ bool WINAPI SFileAddFileEx(
ULONGLONG FileSize = 0;
ULONGLONG FileTime = 0;
TFileStream * pStream = NULL;
+ TMPQArchive * ha;
HANDLE hMpqFile = NULL;
LPBYTE pbFileData = NULL;
DWORD dwBytesRemaining = 0;
@@ -907,7 +908,7 @@ bool WINAPI SFileAddFileEx(
DWORD dwErrCode = ERROR_SUCCESS;
// Check parameters
- if(hMpq == NULL || szFileName == NULL || *szFileName == 0)
+ if(hMpq == NULL || szFileName == NULL || *szFileName == 0 || (ha = IsValidMpqHandle(hMpq)) == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
return false;
@@ -933,6 +934,13 @@ bool WINAPI SFileAddFileEx(
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
}
+ // LZMA compression can only be present in MPQ version 2 or higher
+ if(dwErrCode == ERROR_SUCCESS)
+ {
+ if(dwCompression == MPQ_COMPRESSION_LZMA && ha->pHeader->wFormatVersion == MPQ_FORMAT_VERSION_1)
+ dwErrCode = ERROR_INVALID_PARAMETER;
+ }
+
// Deal with various combination of compressions
if(dwErrCode == ERROR_SUCCESS)
{
diff --git a/src/SFileCreateArchive.cpp b/src/SFileCreateArchive.cpp
index 4266070..c0ea367 100644
--- a/src/SFileCreateArchive.cpp
+++ b/src/SFileCreateArchive.cpp
@@ -27,6 +27,13 @@ static const DWORD MpqHeaderSizes[] =
//-----------------------------------------------------------------------------
// Local functions
+static DWORD GetValidFileFlags(DWORD dwMpqVersion)
+{
+ if(dwMpqVersion > MPQ_FORMAT_VERSION_1)
+ return MPQ_FILE_VALID_FLAGS;
+ return MPQ_FILE_VALID_FLAGS_W3X;
+}
+
static USHORT GetSectorSizeShift(DWORD dwSectorSize)
{
USHORT wSectorSizeShift = 0;
@@ -211,7 +218,7 @@ bool WINAPI SFileCreateArchive2(const TCHAR * szMpqName, PSFILE_CREATE_MPQ pCrea
ha->dwMaxFileCount = dwHashTableSize;
ha->dwFileTableSize = 0;
ha->dwReservedFiles = dwReservedFiles;
- ha->dwValidFileFlags = (pCreateInfo->dwMpqVersion > 1) ? MPQ_FILE_VALID_FLAGS : MPQ_FILE_VALID_FLAGS_W3X;
+ ha->dwValidFileFlags = GetValidFileFlags(pCreateInfo->dwMpqVersion);
ha->dwFileFlags1 = pCreateInfo->dwFileFlags1;
ha->dwFileFlags2 = pCreateInfo->dwFileFlags2;
ha->dwFileFlags3 = pCreateInfo->dwFileFlags3 ? MPQ_FILE_EXISTS : 0;