-
Notifications
You must be signed in to change notification settings - Fork 26
feat(kvs): enforce maximum key length of 32 bytes (C++) #308
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,17 @@ score::Result<std::unordered_map<std::string, KvsValue>> Kvs::parse_json_data(co | |
| auto sv = element.first.GetAsStringView(); | ||
| std::string key(sv.data(), sv.size()); | ||
|
|
||
| /* FEAT_REQ__KVS__maximum_size: keys read from persistent storage are not | ||
| guaranteed to satisfy the limit (e.g. externally edited or corrupted | ||
| files). Skip over-length keys so they never enter the store. */ | ||
| if (!is_key_length_valid(key)) | ||
| { | ||
| logger->LogWarn() << "Skipping key with length " << key.length() | ||
| << " exceeding maximum allowed " << KVS_MAX_KEY_LENGTH_BYTES | ||
| << " bytes while loading"; | ||
| continue; | ||
|
Contributor
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. This is a quiet failure based on invalid assumption. Make it an error and halt the execution. |
||
| } | ||
|
|
||
| auto conv = any_to_kvsvalue(element.second); | ||
| if (!conv) | ||
| { | ||
|
|
@@ -429,9 +440,24 @@ score::Result<bool> Kvs::is_value_default(const std::string_view key) const | |
| } | ||
| } | ||
|
|
||
| /* FEAT_REQ__KVS__maximum_size: single check for the key-length rule. | ||
| std::string_view::length() counts bytes, matching the byte-based requirement. */ | ||
| bool Kvs::is_key_length_valid(std::string_view key) | ||
|
Contributor
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. This helper don't have to rely on anything |
||
| { | ||
| return key.length() <= KVS_MAX_KEY_LENGTH_BYTES; | ||
| } | ||
|
|
||
| /* Set the value for a key*/ | ||
| score::ResultBlank Kvs::set_value(const std::string_view key, const KvsValue& value) | ||
| { | ||
| /* FEAT_REQ__KVS__maximum_size: reject keys that exceed the maximum length. */ | ||
|
Contributor
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. Invalid req, like in other places. |
||
| if (!is_key_length_valid(key)) | ||
| { | ||
| logger->LogError() << "Key length " << key.length() << " exceeds maximum allowed " | ||
|
Contributor
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. Same here - check whitespace behavior. |
||
| << KVS_MAX_KEY_LENGTH_BYTES << " bytes"; | ||
| return score::MakeUnexpected(ErrorCode::KeyTooLong); | ||
| } | ||
|
|
||
| score::ResultBlank result = score::MakeUnexpected(ErrorCode::UnmappedError); | ||
| std::unique_lock<std::mutex> lock(kvs_mutex, std::try_to_lock); | ||
| if (lock.owns_lock()) | ||
|
|
||
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 is simply invalid. Files are either expected to satisfy the limit or are incorrect.
BTW
comp_req__kvs__key_lengthis the right req.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.
Your points have been resolved.