mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Fix check paths
This commit is contained in:
@ -217,6 +217,17 @@ namespace ZLibZipUtils
|
|||||||
pos += replace.length();
|
pos += replace.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void replace_all_w(std::wstring& subject, const std::wstring& search, const std::wstring& replace)
|
||||||
|
{
|
||||||
|
size_t pos = 0;
|
||||||
|
while ((pos = subject.find(search, pos)) != std::wstring::npos)
|
||||||
|
{
|
||||||
|
subject.replace(pos, search.length(), replace);
|
||||||
|
pos += replace.length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int do_extract_currentfile( unzFile uf, const wchar_t* unzip_dir, const int* popt_extract_without_path, int* popt_overwrite, const char* password )
|
static int do_extract_currentfile( unzFile uf, const wchar_t* unzip_dir, const int* popt_extract_without_path, int* popt_overwrite, const char* password )
|
||||||
{
|
{
|
||||||
char filename_inzipA[4096];
|
char filename_inzipA[4096];
|
||||||
@ -279,31 +290,28 @@ namespace ZLibZipUtils
|
|||||||
}
|
}
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
char* current_directory = getcwd(NULL, 0);
|
if (unzip_dir)
|
||||||
|
|
||||||
if (current_directory)
|
|
||||||
{
|
{
|
||||||
std::string current_path(current_directory);
|
std::wstring current_path(unzip_dir);
|
||||||
free(current_directory);
|
current_path += FILE_SEPARATOR_STR;
|
||||||
|
|
||||||
current_path += FILE_SEPARATOR_STRA;
|
replace_all_w(current_path, L"/", FILE_SEPARATOR_STR);
|
||||||
|
replace_all_w(current_path, L"\\", FILE_SEPARATOR_STR);
|
||||||
|
|
||||||
replace_all(current_path, "/", FILE_SEPARATOR_STRA);
|
std::wstring filename_inzip(filenameW);
|
||||||
replace_all(current_path, "\\", FILE_SEPARATOR_STRA);
|
|
||||||
|
|
||||||
std::string filename_inzip(filename_inzipA);
|
replace_all_w(filename_inzip, L"/", FILE_SEPARATOR_STR);
|
||||||
|
replace_all_w(filename_inzip, L"\\", FILE_SEPARATOR_STR);
|
||||||
|
|
||||||
replace_all(filename_inzip, "/", FILE_SEPARATOR_STRA);
|
std::wstring norm_path = NSSystemPath::NormalizePath(current_path + filename_inzip);
|
||||||
replace_all(filename_inzip, "\\", FILE_SEPARATOR_STRA);
|
std::wstring norm_current_path = NSSystemPath::NormalizePath(current_path);
|
||||||
|
|
||||||
std::string norm_path = NSSystemPath::NormalizePath(current_path + filename_inzip);
|
if (std::wstring::npos == norm_path.find(norm_current_path))
|
||||||
std::string norm_current_path = NSSystemPath::NormalizePath(current_path);
|
|
||||||
|
|
||||||
if (std::string::npos == norm_path.find(norm_current_path))
|
|
||||||
{
|
{
|
||||||
return UNZ_INTERNALERROR;
|
return UNZ_INTERNALERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
NSFile::CFileBinary oFile;
|
NSFile::CFileBinary oFile;
|
||||||
FILE *fout = NULL;
|
FILE *fout = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user