fix: relax collection path restriction (#340)

This commit is contained in:
Jalin Wang
2026-04-16 15:26:15 +08:00
committed by GitHub
parent 37cd226410
commit 95d092e9b3
5 changed files with 29 additions and 31 deletions
+2 -2
View File
@@ -1725,9 +1725,9 @@ Status CollectionImpl::create() {
if (path_.empty()) {
return Status::InvalidArgument("path validate failed: path is empty");
}
if (!std::regex_match(path_, COLLECTION_PATH_REGEX)) {
if (!FileHelper::PathSimpleValidation(path_)) {
return Status::InvalidArgument("path validate failed: path[", path_,
"] cannot pass the regex verification");
"] is not a valid path");
}
if (ailego::FileHelper::IsExist(path_.c_str())) {
return Status::InvalidArgument("path validate failed: path[", path_,
-3
View File
@@ -46,9 +46,6 @@ const std::regex FIELD_NAME_REGEX("^[a-zA-Z0-9_-]{1,32}$");
const std::regex DOC_PK_REGEX("^[a-zA-Z0-9_!@#$%+=.-]{1,64}$");
const std::regex COLLECTION_PATH_REGEX(
R"(^(?:[a-zA-Z]:)?[/\\]?(?:[a-zA-Z0-9_.\-]+[/\\])*[a-zA-Z0-9_.\-]+$)");
constexpr uint32_t kMaxDenseDimSize = 20000;
constexpr uint32_t kMaxScalarFieldSize = 1024;
+16
View File
@@ -231,6 +231,22 @@ class FileHelper {
return ailego::FileHelper::FileSize(file_path.c_str());
}
//! Perform a lightweight sanity check on the path string.
//! This only catches obvious invalid input and does NOT guarantee the path
//! is usable.
static bool PathSimpleValidation(const std::string &path) {
if (path.empty()) return false;
if (path.find('\0') != std::string::npos) return false;
#ifdef _WIN32
// Characters forbidden in Windows path components.
if (path.find_first_of("<>\"|?*") != std::string::npos) return false;
#endif
return true;
}
//! Copy file
//! src_file_path and dst_file_path must be the full path
//! dst_file_path/.. must exist