Skip to content
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 3 commits into from
Apr 17, 2024

Conversation

muhammadhamzasajjad
Copy link
Collaborator

Reference Issues/PRs

Fixes #1247

What does this implement or fix?

Any other comments?

Checklist

Checklist for code changes...
  • Have you updated the relevant docstrings, documentation and copyright notice?
  • Is this contribution tested against all ArcticDB's features?
  • Do all exceptions introduced raise appropriate error messages?
  • Are API changes highlighted in the PR description?
  • Is the PR labelled as enhancement or bug so it appears in autogenerated release notes?

@muhammadhamzasajjad muhammadhamzasajjad self-assigned this Apr 8, 2024
@muhammadhamzasajjad muhammadhamzasajjad added the bug Something isn't working label Apr 9, 2024
@muhammadhamzasajjad muhammadhamzasajjad force-pushed the lmdb_invalid_lib_name branch 3 times, most recently from 8b5fc3f to 60a1161 Compare April 15, 2024 16:40
@muhammadhamzasajjad muhammadhamzasajjad marked this pull request as ready for review April 16, 2024 12:57
@DrNickClarke
Copy link
Contributor

Looks good to me

Comment on lines 106 to 118
def test_invalid_lib_name_windows(lmdb_storage):
ac = lmdb_storage.create_arctic()

invalid_paths = ["lib?1", "lib:1", "lib|1", "lib.", "lib "]
for lib in invalid_paths:
with pytest.raises(UserInputException) as e:
ac.create_library(lib)
assert ac.list_libraries() == []

valid_libs = ["lib#~@,1", "lib{)[.1", "!lib$%^"]
for lib in valid_libs:
ac.create_library(lib)
assert set(ac.list_libraries()) == set(valid_libs)
Copy link
Collaborator

@vasil-pashov vasil-pashov Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd split this into two separate test cases because it looks like it's testing two separate things. One is that some strings are valid and the other is that some strings are invalid. The name is confusing as well. Also it looks like the naming is inconsistent, it's paths in one place and libs in the other. I'd also use parametrized test in order to avoid the for lib in invalid_paths loop. It would look a lot cleaner as the test would have only the asserts in it's body.

@pytest.mark.skipif(sys.platform == "win32", reason="Windows has different file path name restrictions")
def test_valid_lib_name_linux(lmdb_storage):
ac = lmdb_storage.create_arctic()
valid_libs = ["lib?1", "lib:1", "lib|1", "lib ", "lib#~@,1", "lib{)[.1", "!lib$%^"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use parametrized test

Comment on lines 114 to 118
def is_valid_lmdb_lib_name(lmdb_storage, lib_name):
ac = lmdb_storage.create_arctic()
ac.create_library(lib_name)

return ac.list_libraries() == [lib_name]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add this inside the tests instead of separating it in a function. While it helps avoiding code duplication it has the side effect of actually creating a library. I wouldn't expect a function checking if the name is valid to create a library.

@muhammadhamzasajjad muhammadhamzasajjad merged commit 1572029 into master Apr 17, 2024
115 checks passed
@muhammadhamzasajjad muhammadhamzasajjad deleted the lmdb_invalid_lib_name branch April 17, 2024 09:17
@@ -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 = "<>:\"|?*";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@muhammadhamzasajjad muhammadhamzasajjad Apr 17, 2024

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 give name1/name2 it will just create a subdir name2 under name1 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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

return false;
}
#else
(void) pathString; // suppress -Werror=unused-parameter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ARCTICDB_UNUSED instead of this

verify_name("library name", library_path, true, UNSUPPORTED_S3_CHARS);
if(!store->is_path_valid(library_path)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get rid of this if using user_input::check

muhammadhamzasajjad added a commit that referenced this pull request Apr 17, 2024
muhammadhamzasajjad added a commit that referenced this pull request Apr 18, 2024
#### Reference Issues/PRs
Addresses @alexowens90's comments in #1481 after that PR was merged.

#### What does this implement or fix?

#### Any other comments?

#### Checklist

<details>
  <summary>
   Checklist for code changes...
  </summary>
 
- [ ] Have you updated the relevant docstrings, documentation and
copyright notice?
- [ ] Is this contribution tested against [all ArcticDB's
features](../docs/mkdocs/docs/technical/contributing.md)?
- [ ] Do all exceptions introduced raise appropriate [error
messages](https://docs.arcticdb.io/error_messages/)?
 - [ ] Are API changes highlighted in the PR description?
- [ ] Is the PR labelled as enhancement or bug so it appears in
autogenerated release notes?
</details>

<!--
Thanks for contributing a Pull Request to ArcticDB! Please ensure you
have taken a look at:
- ArcticDB's Code of Conduct:
https://github.com/man-group/ArcticDB/blob/master/CODE_OF_CONDUCT.md
- ArcticDB's Contribution Licensing:
https://github.com/man-group/ArcticDB/blob/master/docs/mkdocs/docs/technical/contributing.md#contribution-licensing
-->
grusev pushed a commit that referenced this pull request Nov 25, 2024
)

#### Reference Issues/PRs
Fixes #1247 

#### What does this implement or fix?

#### Any other comments?

#### Checklist

<details>
  <summary>
   Checklist for code changes...
  </summary>
 
- [ ] Have you updated the relevant docstrings, documentation and
copyright notice?
- [ ] Is this contribution tested against [all ArcticDB's
features](../docs/mkdocs/docs/technical/contributing.md)?
- [ ] Do all exceptions introduced raise appropriate [error
messages](https://docs.arcticdb.io/error_messages/)?
 - [ ] Are API changes highlighted in the PR description?
- [ ] Is the PR labelled as enhancement or bug so it appears in
autogenerated release notes?
</details>
grusev pushed a commit that referenced this pull request Nov 25, 2024
#### Reference Issues/PRs
Addresses @alexowens90's comments in #1481 after that PR was merged.

#### What does this implement or fix?

#### Any other comments?

#### Checklist

<details>
  <summary>
   Checklist for code changes...
  </summary>
 
- [ ] Have you updated the relevant docstrings, documentation and
copyright notice?
- [ ] Is this contribution tested against [all ArcticDB's
features](../docs/mkdocs/docs/technical/contributing.md)?
- [ ] Do all exceptions introduced raise appropriate [error
messages](https://docs.arcticdb.io/error_messages/)?
 - [ ] Are API changes highlighted in the PR description?
- [ ] Is the PR labelled as enhancement or bug so it appears in
autogenerated release notes?
</details>

<!--
Thanks for contributing a Pull Request to ArcticDB! Please ensure you
have taken a look at:
- ArcticDB's Code of Conduct:
https://github.com/man-group/ArcticDB/blob/master/CODE_OF_CONDUCT.md
- ArcticDB's Contribution Licensing:
https://github.com/man-group/ArcticDB/blob/master/docs/mkdocs/docs/technical/contributing.md#contribution-licensing
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LMDB on Windows creates unusable libraries when using invalid characters
4 participants