Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyakovKirill committed Feb 14, 2024
1 parent 33c5852 commit a6a73ff
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
12 changes: 6 additions & 6 deletions DesktopEditor/raster/Metafile/svg/SvgObjects/CImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ namespace SVG
if (NSProcessEnv::IsPresent(NSProcessEnv::Converter::gc_allowPrivateIP))
bIsAllowExternalLocalFiles = NSProcessEnv::GetBoolValue(NSProcessEnv::Converter::gc_allowPrivateIP);

if (bIsAllowExternalLocalFiles || (!wsFilePath.empty() && L'.' != wsFilePath[0]))
{
wsFilePath = pFile->GetWorkingDirectory() + L'/' + wsFilePath;
if (!bIsAllowExternalLocalFiles && wsFilePath.length() >= 3 && L"../" == wsFilePath.substr(0, 3))
return true;

if (!NSFile::CFileBinary::Exists(wsFilePath) || !NSFile::CFileBinary::ReadAllBytes(wsFilePath, &pBuffer, ulSize))
return false;
}
wsFilePath = pFile->GetWorkingDirectory() + L'/' + wsFilePath;

if (!NSFile::CFileBinary::Exists(wsFilePath) || !NSFile::CFileBinary::ReadAllBytes(wsFilePath, &pBuffer, ulSize))
return false;
#endif

if (NULL == pBuffer)
Expand Down
36 changes: 27 additions & 9 deletions HtmlFile2/htmlfile2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ std::wstring EncodeXmlString(const std::wstring& s)
return sRes;
}

bool GetStatusUsingExternalLocalFiles()
{
if (NSProcessEnv::IsPresent(NSProcessEnv::Converter::gc_allowPrivateIP))
return NSProcessEnv::GetBoolValue(NSProcessEnv::Converter::gc_allowPrivateIP);

return true;
}

bool CanUseThisPath(const std::wstring& wsPath, bool bIsAllowExternalLocalFiles)
{
if (bIsAllowExternalLocalFiles)
return true;

if (wsPath.length() >= 3 && L"../" == wsPath.substr(0, 3))
return false;

return true;
}

class CHtmlFile2_Private
{
public:
Expand Down Expand Up @@ -1849,9 +1868,12 @@ class CHtmlFile2_Private
return;
}

bool bIsAllowExternalLocalFiles = true;
if (NSProcessEnv::IsPresent(NSProcessEnv::Converter::gc_allowPrivateIP))
bIsAllowExternalLocalFiles = NSProcessEnv::GetBoolValue(NSProcessEnv::Converter::gc_allowPrivateIP);
const bool bIsAllowExternalLocalFiles = GetStatusUsingExternalLocalFiles();

sSrcM = NSSystemPath::ShortenPath(sSrcM);

if (!CanUseThisPath(sSrcM, bIsAllowExternalLocalFiles))
return;

int nImageId = -1;
std::wstring sImageSrc, sExtention;
Expand Down Expand Up @@ -2145,13 +2167,9 @@ class CHtmlFile2_Private
if(nHRefLen == std::wstring::npos)
break;

std::wstring sImageName = NSSystemPath::ShortenPath(sSVG.substr(nHRef, nHRefLen - nHRef));

bool bIsAllowExternalLocalFiles = true;
if (NSProcessEnv::IsPresent(NSProcessEnv::Converter::gc_allowPrivateIP))
bIsAllowExternalLocalFiles = NSProcessEnv::GetBoolValue(NSProcessEnv::Converter::gc_allowPrivateIP);
const std::wstring sImageName = NSSystemPath::ShortenPath(sSVG.substr(nHRef, nHRefLen - nHRef));

if (!bIsAllowExternalLocalFiles && !sImageName.empty() && L'.' == sImageName[0])
if (!CanUseThisPath(sImageName, GetStatusUsingExternalLocalFiles()))
break;

std::wstring sTIN(sImageName);
Expand Down

0 comments on commit a6a73ff

Please sign in to comment.