-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix/1247: Don't create an lmdb library if the name is invalid. #1481
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,23 @@ void LmdbStorage::do_iterate_type(KeyType key_type, const IterateTypeVisitor& vi | |
} | ||
} | ||
|
||
bool LmdbStorage::do_is_path_valid(const std::string_view pathString) const { | ||
#ifdef _WIN32 | ||
std::string_view invalid_win32_chars = "<>:\"|?*"; | ||
auto found = pathString.find_first_of(invalid_win32_chars); | ||
if (found != std::string::npos) { | ||
return false; | ||
} | ||
|
||
if (!pathString.empty() && (pathString.back() == '.' || std::isspace(pathString.back()))) { | ||
return false; | ||
} | ||
#else | ||
(void) pathString; // suppress -Werror=unused-parameter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
#endif | ||
return true; | ||
} | ||
|
||
void remove_db_files(const fs::path& lib_path) { | ||
std::vector<std::string> files = {"lock.mdb", "data.mdb"}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
#include <arcticdb/entity/types.hpp> | ||
#include <arcticdb/util/configs_map.hpp> | ||
#include <arcticdb/stream/index.hpp> | ||
#include <arcticdb/storage/store.hpp> | ||
|
||
namespace arcticdb { | ||
|
||
|
@@ -118,8 +119,14 @@ void verify_library_path_part(const std::string& library_part, char delim) { | |
} | ||
} | ||
|
||
void verify_library_path_on_write(const StringId& library_path) { | ||
void verify_library_path_on_write(const Store* store, const StringId& library_path) { | ||
verify_name("library name", library_path, true, UNSUPPORTED_S3_CHARS); | ||
if(!store->is_path_valid(library_path)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can get rid of this |
||
user_input::raise<ErrorCode::E_INVALID_CHAR_IN_NAME>( | ||
"The library name contains unsupported chars. Library Name: {}", | ||
library_path | ||
); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This list is not exhaustive:
https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names
There are also a whole bunch of other reserved filenames that would fail
https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that when we create an lmdb library, it creates a folder with the given name, therefore I allow
/
and\
as in this case if you givename1/name2
it will just create a subdirname2
undername1
and everything else (e.g. reads and writes on the lib) will work fine. In fact, this older test expects to be able to create such libraries. The purpose of this fix is to strictly disallow library names that are disallowed by windows, and a library name containing/
or\
would not fail so they should be allowed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did look at the list of other reserved filenames while working on the fix. But the docs were strictly saying "reserved names for the name of a file". In fact, I tested this and I was able to create libraries with names such as
CON, PRN, COM0
which successfully created folders with these names. These are reserved names but not strictly disallowed and that's why I allowed these names.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha OK that makes sense. I think it's worth adding a comment here explaining all this, as it won't be obvious to the next person reading it.