feat(kvs): enforce maximum key length of 32 bytes (C++) - #308
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run --lockfile_mode=error //:license-checkStatus: Click to expand output |
|
The created documentation from the pull request is available at: docu-html |
arkjedrz
left a comment
There was a problem hiding this comment.
Replace PR description with a human-made one. Current is both inconcise and wrong.
| auto sv = element.first.GetAsStringView(); | ||
| std::string key(sv.data(), sv.size()); | ||
|
|
||
| /* FEAT_REQ__KVS__maximum_size: keys read from persistent storage are not |
There was a problem hiding this comment.
This is simply invalid. Files are either expected to satisfy the limit or are incorrect.
BTW comp_req__kvs__key_length is the right req.
There was a problem hiding this comment.
Your points have been resolved.
| logger->LogWarn() << "Skipping key with length " << key.length() | ||
| << " exceeding maximum allowed " << KVS_MAX_KEY_LENGTH_BYTES | ||
| << " bytes while loading"; | ||
| continue; |
There was a problem hiding this comment.
This is a quiet failure based on invalid assumption. Make it an error and halt the execution.
|
|
||
| /* 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) |
There was a problem hiding this comment.
This helper don't have to rely on anything Kvs class related. Rework it to a function, then place it in anonymous namespace/mark it as static.
| /* 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. */ |
There was a problem hiding this comment.
Invalid req, like in other places.
|
@atarekra there are some comments, please adapt |
arkjedrz
left a comment
There was a problem hiding this comment.
Logging to be confirmed, otherwise LGTM.
| loading with an error rather than silently dropping data. */ | ||
| if (!is_key_length_valid(key)) | ||
| { | ||
| logger->LogError() << "Key length " << key.length() << " exceeds maximum allowed " |
There was a problem hiding this comment.
Please check for whitespaces - IIRC spaces are already inserted between streamed fields (e.g., "Key length " << key.length() will show Key length 1234 instead of expected Key length 1234).
| /* comp_req__kvs__key_length: reject keys that exceed the maximum length. */ | ||
| if (!is_key_length_valid(key)) | ||
| { | ||
| logger->LogError() << "Key length " << key.length() << " exceeds maximum allowed " |
There was a problem hiding this comment.
Same here - check whitespace behavior.
|
Thanks for the pull request. This thread has been quiet for 30 days, so we are marking it as stale for now. Please take a quick look and let us know whether it is still up to date, still relevant, needs review, or is ready to merge. Any new activity will remove the stale label automatically. If nothing changes in the next 10 days, we will close it to keep the backlog current. |
Summary
Enforces the maximum key length for the C++ KVS, implementing
comp_req__kvs__key_lengthChanges
KVS_MAX_KEY_LENGTH_BYTES(32) constant and a file-localis_key_length_valid()helper used as the single source of truth for the rule.set_value()rejects keys longer than the limit and returns the newErrorCode::KeyTooLong.parse_json_data()treats an over-length key found while loading as an invalidor corrupted file: it halts loading and returns
ErrorCode::KeyTooLongratherthan silently dropping the entry.
KeyTooLongerror code and its message.Tests
set_valueaccepts a key of exactly 32 bytes and rejects a 33-byte key withKeyTooLong.parse_json_datareturnsKeyTooLongwhen a loaded object contains anover-length key.
MessageForcovers the new error code.Notes
std::string_view::length()counts bytes, matchingthe requirement.