diff --git a/OFDFile/src/Base.cpp b/OFDFile/src/Base.cpp index 88f0298c99..59404d12d4 100644 --- a/OFDFile/src/Base.cpp +++ b/OFDFile/src/Base.cpp @@ -57,10 +57,13 @@ bool CDocInfo::Read(CXmlReader& oLiteReader) return true; } -void CDocBody::ReadSignatures(const std::wstring& wsFilePath, const std::wstring& wsRootPath) +void CDocBody::ReadSignatures(const std::wstring& wsFilePath, IFolder* pFolder) { + if (wsFilePath.empty() || !CanUseThisPath(wsFilePath, pFolder->getFullFilePath(L""))) + return; + CXmlReader oLiteReader; - if (!oLiteReader.FromFile(CombinePaths(wsRootPath, wsFilePath)) || !oLiteReader.ReadNextNode() || L"ofd:Signatures" != oLiteReader.GetName()) + if (!oLiteReader.FromFile(CombinePaths(pFolder->getFullFilePath(L""), wsFilePath)) || !oLiteReader.ReadNextNode() || L"ofd:Signatures" != oLiteReader.GetName()) return; const int nDepth = oLiteReader.GetDepth(); @@ -81,7 +84,7 @@ void CDocBody::ReadSignatures(const std::wstring& wsFilePath, const std::wstring do { if ("BaseLoc" == oLiteReader.GetNameA()) - AddToContainer(CSignature::Read(oLiteReader.GetText(), wsRootPath), m_arSignatures); + AddToContainer(CSignature::Read(oLiteReader.GetText(), pFolder), m_arSignatures); } while (oLiteReader.MoveToNextAttribute()); oLiteReader.MoveToElement(); @@ -123,14 +126,9 @@ CDocBody* CDocBody::Read(CXmlReader& oLiteReader, IFolder* pFolder) } } else if ("ofd:DocRoot" == sNodeName) - { - const std::wstring wsPath = NSSystemPath::ShortenPath(oLiteReader.GetText2()); - - if (!wsPath.empty() && L'.' != wsPath.front()) - pDocBody->m_oDocument.Read(pFolder->getFullFilePath(wsPath)); - } + pDocBody->m_oDocument.Read(oLiteReader.GetText2(), pFolder); else if ("ofd:Signatures" == sNodeName) - pDocBody->ReadSignatures(oLiteReader.GetText2(), pFolder->getFullFilePath(L"")); + pDocBody->ReadSignatures(oLiteReader.GetText2(), pFolder); } return pDocBody; diff --git a/OFDFile/src/Base.h b/OFDFile/src/Base.h index 7f07db7884..a10c281b3b 100644 --- a/OFDFile/src/Base.h +++ b/OFDFile/src/Base.h @@ -45,11 +45,10 @@ class CDocBody { CDocInfo m_oDocInfo; CDocument m_oDocument; - // std::wstring m_wsPathToDocRoot; // std::wstring m_wsVersions; std::vector m_arSignatures; - void ReadSignatures(const std::wstring& wsFilePath, const std::wstring& wsRootPath); + void ReadSignatures(const std::wstring& wsFilePath, IFolder* pFolder); public: CDocBody(); ~CDocBody(); diff --git a/OFDFile/src/Document.cpp b/OFDFile/src/Document.cpp index b9568a7cfc..272bcbce7f 100644 --- a/OFDFile/src/Document.cpp +++ b/OFDFile/src/Document.cpp @@ -44,15 +44,16 @@ bool CDocument::Empty() const return m_mPages.empty(); } -bool CDocument::Read(const std::wstring& wsFilePath) +bool CDocument::Read(const std::wstring& wsFilePath, IFolder* pFolder) { - if (wsFilePath.empty()) + if (wsFilePath.empty() || !CanUseThisPath(wsFilePath, pFolder->getFullFilePath(L""))) return false; CXmlReader oLiteReader; - if (!oLiteReader.FromFile(wsFilePath) || !oLiteReader.ReadNextNode() || L"ofd:Document" != oLiteReader.GetName()) + if (!oLiteReader.FromFile(pFolder->getFullFilePath(wsFilePath)) || !oLiteReader.ReadNextNode() || L"ofd:Document" != oLiteReader.GetName()) return false; + const std::wstring wsCoreDirectory{pFolder->getFullFilePath(NSSystemPath::GetDirectoryName(wsFilePath))}; const int nDepth = oLiteReader.GetDepth(); std::wstring wsNodeName; @@ -61,7 +62,7 @@ bool CDocument::Read(const std::wstring& wsFilePath) wsNodeName = oLiteReader.GetName(); if (L"ofd:CommonData" == wsNodeName) - m_oCommonData.Read(oLiteReader, NSSystemPath::GetDirectoryName(wsFilePath)); + m_oCommonData.Read(oLiteReader, wsCoreDirectory); else if (L"ofd:Pages" == wsNodeName) { const int nPagesDepth = oLiteReader.GetDepth(); @@ -69,6 +70,7 @@ bool CDocument::Read(const std::wstring& wsFilePath) int nID = -1; std::wstring wsBaseLoc; + while (oLiteReader.ReadNextSiblingNode(nPagesDepth)) { if (L"ofd:Page" != oLiteReader.GetName() || 2 > oLiteReader.GetAttributesCount() || !oLiteReader.MoveToFirstAttribute()) @@ -88,7 +90,7 @@ bool CDocument::Read(const std::wstring& wsFilePath) if (-1 == nID) nID = m_mPages.size() + 1; - CPage* pPage = CPage::Read(CombinePaths(NSSystemPath::GetDirectoryName(wsFilePath), wsBaseLoc)); + CPage* pPage = CPage::Read(wsBaseLoc, wsCoreDirectory); if (nullptr != pPage) m_mPages.insert(std::make_pair(m_mPages.size(), pPage)); diff --git a/OFDFile/src/Document.h b/OFDFile/src/Document.h index 50bb0afc95..ee7f265c77 100644 --- a/OFDFile/src/Document.h +++ b/OFDFile/src/Document.h @@ -4,7 +4,7 @@ #include "Page.h" #include "../../DesktopEditor/graphics/IRenderer.h" -#include "../../DesktopEditor/graphics/pro/Fonts.h" +#include "../../OfficeUtils/src/ZipFolder.h" namespace OFD { @@ -34,7 +34,7 @@ public: bool Empty() const; - bool Read(const std::wstring& wsFilePath); + bool Read(const std::wstring& wsFilePath, IFolder* pFolder); bool DrawPage(IRenderer* pRenderer, int nPageIndex) const; diff --git a/OFDFile/src/Page.cpp b/OFDFile/src/Page.cpp index a96be0ac9f..34a47a28c4 100644 --- a/OFDFile/src/Page.cpp +++ b/OFDFile/src/Page.cpp @@ -13,12 +13,12 @@ CPage::CPage() CPage::~CPage() {} -CPage* CPage::Read(const std::wstring& wsFilePath) +CPage* CPage::Read(const std::wstring& wsFilePath, const std::wstring& wsRootPath) { - if (wsFilePath.empty()) + if (wsFilePath.empty() || !CanUseThisPath(wsFilePath, wsRootPath)) return nullptr; - std::wstring wsNormalizedPath = wsFilePath; + std::wstring wsNormalizedPath = CombinePaths(wsRootPath, wsFilePath); if (L"xml" != NSFile::GetFileExtention(wsNormalizedPath)) wsNormalizedPath = CombinePaths(wsNormalizedPath, L"Content.xml"); diff --git a/OFDFile/src/Page.h b/OFDFile/src/Page.h index c8fa772639..09d16e5130 100644 --- a/OFDFile/src/Page.h +++ b/OFDFile/src/Page.h @@ -17,7 +17,7 @@ public: CPage(); ~CPage(); - static CPage* Read(const std::wstring& wsFilePath); + static CPage* Read(const std::wstring& wsFilePath, const std::wstring& wsRootPath); void Draw(IRenderer* pRenderer, const CCommonData& oCommonData) const; void GetPageSize(double& dWidth, double& dHeight) const; diff --git a/OFDFile/src/Res.cpp b/OFDFile/src/Res.cpp index d1d9f39008..6ad11a11a9 100644 --- a/OFDFile/src/Res.cpp +++ b/OFDFile/src/Res.cpp @@ -36,16 +36,18 @@ inline void AddElementToMap(T* pElement, unsigned int unIndex, std::mapRead(CombinePaths(wsRootPath, oLiteReader.GetText2())); + m_pPublicRes->Read(oLiteReader.GetText2(), wsRootPath); } else if ("ofd:DocumentRes" == sNodeName) { if(nullptr == m_pDocumentRes) m_pDocumentRes = new CRes(); - m_pDocumentRes->Read(CombinePaths(wsRootPath, oLiteReader.GetText2())); + m_pDocumentRes->Read(oLiteReader.GetText2(), wsRootPath); } else if ("ofd:MaxUnitID" == sNodeName) m_unMaxUnitID = oLiteReader.GetUInteger(); diff --git a/OFDFile/src/Types/Font.cpp b/OFDFile/src/Types/Font.cpp index 56cd1b2767..a596884160 100644 --- a/OFDFile/src/Types/Font.cpp +++ b/OFDFile/src/Types/Font.cpp @@ -45,7 +45,11 @@ CFont::CFont(CXmlReader& oXmlReader, const std::wstring& wsRootPath) { if ("ofd:FontFile" == oXmlReader.GetNameA()) { - m_wsFilePath = CombinePaths(wsRootPath, oXmlReader.GetText2()); + const std::wstring wsPath{oXmlReader.GetText2()}; + + if (CanUseThisPath(wsPath, wsRootPath)) + m_wsFilePath = CombinePaths(wsRootPath, wsPath); + break; } } diff --git a/OFDFile/src/Types/MultiMedia.cpp b/OFDFile/src/Types/MultiMedia.cpp index ee48fcfd6b..a3cd0ffb04 100644 --- a/OFDFile/src/Types/MultiMedia.cpp +++ b/OFDFile/src/Types/MultiMedia.cpp @@ -39,7 +39,11 @@ CMultiMedia::CMultiMedia(CXmlReader& oXmlReader, const std::wstring& wsRootPath) { if ("ofd:MediaFile" == oXmlReader.GetNameA()) { - m_wsFilePath = CombinePaths(wsRootPath, oXmlReader.GetText2()); + const std::wstring wsPath{oXmlReader.GetText2()}; + + if (CanUseThisPath(wsPath, wsRootPath)) + m_wsFilePath = CombinePaths(wsRootPath, wsPath); + break; } } diff --git a/OFDFile/src/Types/Signature.cpp b/OFDFile/src/Types/Signature.cpp index 59573aeda8..bc82a71427 100644 --- a/OFDFile/src/Types/Signature.cpp +++ b/OFDFile/src/Types/Signature.cpp @@ -9,18 +9,18 @@ namespace OFD CSignature::CSignature() {} -CSignature* CSignature::Read(const std::wstring& wsFilePath, const std::wstring& wsRootPath) +CSignature* CSignature::Read(const std::wstring& wsFilePath, IFolder* pFolder) { - if (wsFilePath.empty()) + if (wsFilePath.empty() || !CanUseThisPath(wsFilePath, pFolder->getFullFilePath(L""))) return nullptr; CXmlReader oLiteReader; - if (!oLiteReader.FromFile(CombinePaths(wsRootPath, wsFilePath)) || !oLiteReader.ReadNextNode() || L"ofd:Signature" != oLiteReader.GetName() || oLiteReader.IsEmptyNode()) + if (!oLiteReader.FromFile(CombinePaths(pFolder->getFullFilePath(L""), wsFilePath)) || !oLiteReader.ReadNextNode() || L"ofd:Signature" != oLiteReader.GetName() || oLiteReader.IsEmptyNode()) return nullptr; CSignature *pSignature = new CSignature(); - pSignature->m_wsRootPath = wsRootPath; + pSignature->m_wsRootPath = pFolder->getFullFilePath(L""); const int nDepth = oLiteReader.GetDepth(); @@ -29,7 +29,7 @@ CSignature* CSignature::Read(const std::wstring& wsFilePath, const std::wstring& if ("ofd:SignedInfo" == oLiteReader.GetNameA()) pSignature->m_oSignedInfo.Read(oLiteReader); else if ("ofd:SignedValue" == oLiteReader.GetNameA()) - pSignature->m_wsSignedValue = CombinePaths(wsRootPath, oLiteReader.GetText2()); + pSignature->m_wsSignedValue = CombinePaths(pSignature->m_wsRootPath, oLiteReader.GetText2()); } return pSignature; diff --git a/OFDFile/src/Types/Signature.h b/OFDFile/src/Types/Signature.h index 439d1e70c1..d2184637c1 100644 --- a/OFDFile/src/Types/Signature.h +++ b/OFDFile/src/Types/Signature.h @@ -3,6 +3,9 @@ #include "../../../DesktopEditor/graphics/pro/Fonts.h" #include "../../../DesktopEditor/graphics/IRenderer.h" + +#include "../../../OfficeUtils/src/ZipFolder.h" + #include "../Utils/XmlReader.h" #include "../Utils/Types.h" @@ -66,7 +69,7 @@ class CSignature public: CSignature(); - static CSignature* Read(const std::wstring& wsFilePath, const std::wstring& wsRootPath); + static CSignature* Read(const std::wstring& wsFilePath, IFolder* pFolder); bool Draw(IRenderer* pRenderer, unsigned int unPageIndex, NSFonts::IApplicationFonts* pFonts) const; }; diff --git a/OFDFile/src/Types/TemplatePage.cpp b/OFDFile/src/Types/TemplatePage.cpp index 41f2f22dfb..4821a10d5f 100644 --- a/OFDFile/src/Types/TemplatePage.cpp +++ b/OFDFile/src/Types/TemplatePage.cpp @@ -1,7 +1,6 @@ #include "TemplatePage.h" #include "../Page.h" -#include "../Utils/Utils.h" namespace OFD { @@ -17,7 +16,7 @@ CTemplatePage::CTemplatePage(CXmlReader& oXmlReader, const std::wstring& wsRootP sAttributeName = oXmlReader.GetNameA(); if ("BaseLoc" == sAttributeName) - m_pPage = CPage::Read(CombinePaths(wsRootPath, oXmlReader.GetText())); + m_pPage = CPage::Read(oXmlReader.GetText(), wsRootPath); else if ("ZOrder" == sAttributeName) m_eZOrder = GetZOrderFromString(oXmlReader.GetTextA()); } while (oXmlReader.MoveToNextAttribute()); diff --git a/OFDFile/src/Utils/Utils.h b/OFDFile/src/Utils/Utils.h index ac277b8598..096f878d9b 100644 --- a/OFDFile/src/Utils/Utils.h +++ b/OFDFile/src/Utils/Utils.h @@ -9,6 +9,9 @@ #include #include "../../../DesktopEditor/common/Path.h" +#include "../../../DesktopEditor/common/ProcessEnv.h" + +#include namespace OFD { @@ -140,6 +143,29 @@ inline std::wstring CombinePaths(const std::wstring& wsFirstPath, const std::wst return NSSystemPath::Combine(wsFirstPath, wsNewSecondPath); } +inline bool GetStatusUsingExternalLocalFiles() +{ + return false; + + if (NSProcessEnv::IsPresent(NSProcessEnv::Converter::gc_allowPrivateIP)) + return NSProcessEnv::GetBoolValue(NSProcessEnv::Converter::gc_allowPrivateIP); + + return true; +} + +inline bool CanUseThisPath(const std::wstring& wsPath, const std::wstring& wsRootPath) +{ + if (GetStatusUsingExternalLocalFiles()) + return true; + + const std::wstring wsFullPath = NSSystemPath::ShortenPath(NSSystemPath::Combine(wsRootPath, wsPath)); + + if (!wsRootPath.empty()) + return boost::starts_with(wsFullPath, wsRootPath); + + return !boost::starts_with(wsFullPath, L"../"); +} + inline bool IsZeroValue(const double& dValue) { return DBL_EPSILON > std::abs(dValue);