@@ -64,6 +64,15 @@ RAPIDJSON_DIAG_PUSH
6464RAPIDJSON_DIAG_OFF (effc++)
6565#endif
6666
67+ #ifdef _WIN32
68+ #include < windows.h>
69+ #include < shlwapi.h>
70+ #endif
71+
72+ #ifndef PATH_MAX
73+ #define PATH_MAX MAX_PATH
74+ #endif
75+
6776using namespace rapidjson ;
6877
6978using namespace rlottie ::internal;
@@ -797,13 +806,27 @@ static std::string convertFromBase64(const std::string &str)
797806 return b64decode (b64Data, length);
798807}
799808
809+ namespace
810+ {
811+ bool Canonicalize (const char *path, char *resolved_path)
812+ {
813+ #ifdef _WIN32
814+ return !!PathCanonicalizeA (resolved_path, path);
815+ #else
816+ return realpath (path, resolved_path);
817+ #endif
818+ }
819+ }
820+
800821static bool isResourcePathSafe (const std::string& baseDir, const std::string& userPath)
801822{
802823 char resolvedBase[PATH_MAX] = {};
803824 char resolvedTarget[PATH_MAX] = {};
804825
805826 // Resolve base directory
806- if (!realpath (baseDir.c_str (), resolvedBase)) {
827+ if (!Canonicalize (baseDir.c_str (), resolvedBase))
828+ {
829+
807830#ifdef DEBUG_PARSER
808831 vWarning << " Error: Cannot resolve base path: " << baseDir.c_str ();
809832#endif
@@ -815,7 +838,7 @@ static bool isResourcePathSafe(const std::string& baseDir, const std::string& us
815838 if (!baseDir.empty () && baseDir.back () != ' /' ) fullPath += " /" ;
816839 fullPath += userPath;
817840
818- if (!realpath (fullPath.c_str (), resolvedTarget)) {
841+ if (!Canonicalize (fullPath.c_str (), resolvedTarget)) {
819842#ifdef DEBUG_PARSER
820843 vWarning << " Error: Cannot resolve target path: " << fullPath.c_str ();
821844#endif
0 commit comments