Skip to content

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

Open
atarekra wants to merge 3 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 3 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: ea399187-0c25-4268-b328-62cd032e37c3
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
Loading: 3 packages loaded
    currently loading: 
Loading: 3 packages loaded
    currently loading: 
Loading: 3 packages loaded
    currently loading: 
Loading: 3 packages loaded
    currently loading: 
Loading: 3 packages loaded
    currently loading: 
Loading: 3 packages loaded
    currently loading: 
Analyzing: target //:license-check (4 packages loaded, 0 targets configured)
Analyzing: target //:license-check (4 packages loaded, 0 targets configured)

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

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

Analyzing: target //:license-check (137 packages loaded, 1106 targets configured)

Analyzing: target //:license-check (139 packages loaded, 2712 targets configured)

Analyzing: target //:license-check (139 packages loaded, 2712 targets configured)

Analyzing: target //:license-check (144 packages loaded, 2725 targets configured)

Analyzing: target //:license-check (153 packages loaded, 5403 targets configured)

Analyzing: target //:license-check (158 packages loaded, 5452 targets configured)

Analyzing: target //:license-check (160 packages loaded, 6476 targets configured)

Analyzing: target //:license-check (161 packages loaded, 7339 targets configured)

Analyzing: target //:license-check (161 packages loaded, 7339 targets configured)

Analyzing: target //:license-check (161 packages loaded, 7339 targets configured)

Analyzing: target //:license-check (161 packages loaded, 7339 targets configured)

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

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

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

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

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

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

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

INFO: Analyzed target //:license-check (166 packages loaded, 10271 targets configured).
[14 / 17] Generating Dash formatted dependency file ...; 0s disk-cache, processwrapper-sandbox ... (2 actions, 1 running)
INFO: From Generating Dash formatted dependency file ...:
INFO: Successfully converted 66 packages from Cargo.lock to bazel-out/k8-fastbuild/bin/formatted.txt
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: 56.906s, Critical Path: 1.99s
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>
[main] INFO Querying Eclipse Foundation for license data for 66 items.
[main] INFO Found 36 items.
[main] INFO Querying ClearlyDefined for license data for 30 items.
[main] INFO Found 30 items.
[main] INFO License information could not be automatically verified for the following content:
[main] INFO 
[main] INFO crate/cratesio/-/score_log/0.0.1
[main] INFO crate/cratesio/-/score_log_fmt/0.0.1
[main] INFO crate/cratesio/-/score_log_fmt_macro/0.0.1
[main] INFO crate/cratesio/-/stdout_logger/0.0.1
[main] INFO crate/cratesio/-/test_scenarios_rust/0.3.0
[main] INFO 
[main] INFO This content is either not correctly mapped by the system, or requires review.
[main] INFO A review is required for crate/cratesio/-/stdout_logger/0.0.1.
[main] INFO A review request already exists https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/work_items/29772 .
[main] INFO A review is required for crate/cratesio/-/test_scenarios_rust/0.3.0.
[main] INFO A review request already exists https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/work_items/29773 .
[main] INFO A review is required for crate/cratesio/-/score_log_fmt/0.0.1.
[main] INFO A review request already exists https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/work_items/29774 .
[main] INFO A review is required for crate/cratesio/-/score_log_fmt_macro/0.0.1.
[main] INFO A review request already exists https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/work_items/29775 .
[main] INFO A review is required for crate/cratesio/-/score_log/0.0.1.
[main] INFO A review request already exists https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/work_items/29776 .

@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 deployed to workflow-approval July 14, 2026 13:45 — with GitHub Actions Active
@atarekra
atarekra requested a deployment to workflow-approval July 14, 2026 16:00 — with GitHub Actions Waiting
@atarekra
atarekra requested a deployment to workflow-approval July 14, 2026 16:00 — with GitHub Actions Waiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants