CheckPath: Better validation routine

This commit is contained in:
2026-04-16 08:09:08 +02:00
parent 48e1f4fb7d
commit fc292a4d71
+4 -1
View File
@@ -8,7 +8,10 @@
#include "JFJochException.h"
inline void CheckPath(const std::string &s) {
if (!s.empty() && s.front() == '/')
// CheckPath looks validates that s can be a valid file name
// (in practice with an added suffix, .e.g. _master.h5 or .tiff)
// It avoids paths going outside of a given directory
if (!s.empty() && (s.front() == '/' || s.back() != '/'))
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
"Path cannot start with slash");
if (s.size() >= 3 && s.substr(0,3) == "../")