Permalink
Browse files

Fix ZipInfo and bug for FileRead reserving not enough memory when fil…

…e has odd number of bytes
  • Loading branch information...
HotKeyIt committed Sep 20, 2017
1 parent 4a30be2 commit 4104cec5b956187f5808550b43207a0e78867441
Showing with 8 additions and 8 deletions.
  1. +1 −1 source/script.cpp
  2. +7 −7 source/script2.cpp
View
@@ -161,7 +161,7 @@ FuncEntry g_BIF[] =
BIF1(ZipAddFolder, 2, 2, true),
BIF1(ZipAddBuffer, 4, 4, true),
BIF1(ZipOptions, 2, 2, true),
BIF1(ZipInfo, 1, 2, true),
BIF1(ZipInfo, 1, 3, true),
BIF1(UnZip, 2, 6, true),
BIF1(UnZipBuffer, 2, 5, true),
View
@@ -8082,7 +8082,7 @@ BIF_DECL(BIF_FileRead)
return;
}
LPBYTE output_buf = (LPBYTE)malloc(size_t(bytes_to_read + sizeof(wchar_t)));
LPBYTE output_buf = (LPBYTE)malloc(size_t(bytes_to_read + (bytes_to_read & 1) + sizeof(wchar_t)));
if (!output_buf)
{
CloseHandle(hfile);
@@ -16158,22 +16158,22 @@ BIF_DECL(BIF_ZipInfo)
// CStringA aPassword = aParamCount > 4 ? CStringCharFromTChar(TokenToString(*aParam[4])) : NULL;
if (TokenIsNumeric(*aParam[0]))
{
if (!TokenIsNumeric(*aParam[1]))
if (aParamCount < 2)
{
g_script->ScriptError(ERR_PARAM2_INVALID);
g_script->ScriptError(ERR_PARAM2_REQUIRED);
aResultToken.SetExitResult(FAIL);
return;
}
else if (aParamCount < 3)
else if (!TokenIsNumeric(*aParam[1]))
{
g_script->ScriptError(ERR_PARAM3_REQUIRED);
g_script->ScriptError(ERR_PARAM2_INVALID);
aResultToken.SetExitResult(FAIL);
return;
}
if (aErrCode = UnzipOpenBuffer(&huz, (void*)TokenToInt64(*aParam[0]), (DWORD)TokenToInt64(*aParam[1]), NULL))
if (aErrCode = UnzipOpenBuffer(&huz, (void*)TokenToInt64(*aParam[0]), (DWORD)TokenToInt64(*aParam[1]), (const char*)(aParamCount == 2 ? NULL : TokenToString(*aParam[2]))))
goto error;
}
else if (aErrCode = UnzipOpenFile(&huz, TokenToString(*aParam[0]), NULL))
else if (aErrCode = UnzipOpenFile(&huz, TokenToString(*aParam[0]), (const char*)(aParamCount == 1 ? NULL : TokenToString(*aParam[1]))))
{
goto error;
}

0 comments on commit 4104cec

Please sign in to comment.