Skip to content

feat(kvs): enforce maximum key length of 32 bytes (C++) - #308

Open
atarekra wants to merge 5 commits into
eclipse-score:mainfrom
Valeo-S-CORE-Organization:Max-KeyLength-Feature
Open

feat(kvs): enforce maximum key length of 32 bytes (C++)#308
atarekra wants to merge 5 commits into
eclipse-score:mainfrom
Valeo-S-CORE-Organization:Max-KeyLength-Feature

Conversation

@atarekra

@atarekra atarekra commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Enforces the maximum key length for the C++ KVS, implementing
comp_req__kvs__key_length

Changes

  • Add KVS_MAX_KEY_LENGTH_BYTES (32) constant and a file-local
    is_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 new
    ErrorCode::KeyTooLong.
  • parse_json_data() treats an over-length key found while loading as an invalid
    or corrupted file: it halts loading and returns ErrorCode::KeyTooLong rather
    than silently dropping the entry.
  • Add the KeyTooLong error code and its message.

Tests

  • set_value accepts a key of exactly 32 bytes and rejects a 33-byte key with
    KeyTooLong.
  • parse_json_data returns KeyTooLong when a loaded object contains an
    over-length key.
  • MessageFor covers the new error code.

Notes

  • The limit is byte-based; std::string_view::length() counts bytes, matching
    the requirement.
  • Rust side is not covered by this PR.

@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

License Check Results

🚀 The license check job ran with the Bazel command:

bazel run --lockfile_mode=error //:license-check

Status: ⚠️ Needs Review

Click to expand output
[License Check Output]
Extracting Bazel installation...
Starting local Bazel server (8.6.0) and connecting to it...
INFO: Invocation ID: d7b06132-ed2d-40f7-b2b5-917887817d9b
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Loading: 
Loading: 3 packages loaded
Analyzing: target //:license-check (4 packages loaded, 0 targets configured)
Analyzing: target //:license-check (4 packages loaded, 0 targets configured)

Analyzing: target //:license-check (71 packages loaded, 10 targets configured)

Analyzing: target //:license-check (90 packages loaded, 10 targets configured)

Analyzing: target //:license-check (142 packages loaded, 953 targets configured)

Analyzing: target //:license-check (149 packages loaded, 3125 targets configured)

Analyzing: target //:license-check (149 packages loaded, 3125 targets configured)

Analyzing: target //:license-check (149 packages loaded, 3125 targets configured)

Analyzing: target //:license-check (163 packages loaded, 6228 targets configured)

Analyzing: target //:license-check (163 packages loaded, 6228 targets configured)

Analyzing: target //:license-check (165 packages loaded, 6357 targets configured)

Analyzing: target //:license-check (173 packages loaded, 9476 targets configured)

Analyzing: target //:license-check (176 packages loaded, 11384 targets configured)

INFO: Analyzed target //:license-check (177 packages loaded, 11510 targets configured).
[6 / 16] Creating runfiles tree bazel-out/k8-fastbuild/bin/license.check.license_check.runfiles; 0s local
[13 / 17] JavaToolchainCompileClasses external/rules_java+/toolchains/platformclasspath_classes; 0s disk-cache, processwrapper-sandbox ... (2 actions running)
INFO: From Generating Dash formatted dependency file ...:
INFO: Successfully converted 66 packages from Cargo.lock to bazel-out/k8-fastbuild/bin/formatted.txt
[15 / 17] JavaToolchainCompileBootClasspath external/rules_java+/toolchains/platformclasspath.jar; 0s disk-cache, processwrapper-sandbox
INFO: Found 1 target...
Target //:license.check.license_check up-to-date:
  bazel-bin/license.check.license_check
  bazel-bin/license.check.license_check.jar
INFO: Elapsed time: 34.448s, Critical Path: 2.75s
INFO: 17 processes: 12 internal, 4 processwrapper-sandbox, 1 worker.
INFO: Build completed successfully, 17 total actions
INFO: Running command line: bazel-bin/license.check.license_check ./formatted.txt <args omitted>
usage: org.eclipse.dash.licenses.cli.Main [-batch <int>] [-cd <url>]
       [-confidence <int>] [-ef <url>] [-excludeSources <sources>] [-help] [-lic
       <url>] [-project <shortname>] [-repo <url>] [-review] [-summary <file>]
       [-timeout <seconds>] [-token <token>]

@github-actions

Copy link
Copy Markdown

The created documentation from the pull request is available at: docu-html

@arkjedrz arkjedrz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Replace PR description with a human-made one. Current is both inconcise and wrong.

Comment thread src/cpp/src/kvs.cpp Outdated
auto sv = element.first.GetAsStringView();
std::string key(sv.data(), sv.size());

/* FEAT_REQ__KVS__maximum_size: keys read from persistent storage are not

Copy link
Copy Markdown
Contributor

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_length is the right req.

Copy link
Copy Markdown
Contributor Author

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.

Comment thread src/cpp/src/kvs.cpp Outdated
logger->LogWarn() << "Skipping key with length " << key.length()
<< " exceeding maximum allowed " << KVS_MAX_KEY_LENGTH_BYTES
<< " bytes while loading";
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Comment thread src/cpp/src/kvs.cpp Outdated

/* 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread src/cpp/src/kvs.cpp Outdated
/* 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. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Invalid req, like in other places.

@atarekra
atarekra temporarily deployed to workflow-approval July 14, 2026 13:45 — with GitHub Actions Inactive
@atarekra
atarekra temporarily deployed to workflow-approval July 14, 2026 13:45 — with GitHub Actions Inactive
@anmittag

Copy link
Copy Markdown
Member

@atarekra there are some comments, please adapt

@atarekra

atarekra commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@atarekra there are some comments, please adapt

if you mean the points mentioned by @arkjedrz , it has been resolved and updated the PR 1 week ago

@arkjedrz arkjedrz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Logging to be confirmed, otherwise LGTM.

Comment thread score/kvs/kvs.cpp Outdated
loading with an error rather than silently dropping data. */
if (!is_key_length_valid(key))
{
logger->LogError() << "Key length " << key.length() << " exceeds maximum allowed "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok working on it

Comment thread score/kvs/kvs.cpp Outdated
/* 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 "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here - check whitespace behavior.

@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale label Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants