Skip to content

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

Merged
PandaeDo merged 1 commit into
eclipse-score:mainfrom
Valeo-S-CORE-Organization:Max-KeyLength-Feature
Oct 12, 2026
Merged

PandaeDo merged 1 commit 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
Contributor

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]
Starting local Bazel server (8.7.0) and connecting to it...
INFO: Invocation ID: 6a49ac2e-8c14-4e2b-959e-f702fc369619
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Loading: 
Loading: 2 packages loaded
Loading: 2 packages loaded
    currently loading: 
Loading: 2 packages loaded
    currently loading: 
Loading: 2 packages loaded
    currently loading: 
Loading: 2 packages loaded
    currently loading: 
Loading: 2 packages loaded
    currently loading: 
Analyzing: target //:license-check (3 packages loaded, 0 targets configured)
Analyzing: target //:license-check (3 packages loaded, 0 targets configured)

Analyzing: target //:license-check (77 packages loaded, 14 targets configured)

Analyzing: target //:license-check (92 packages loaded, 14 targets configured)

Analyzing: target //:license-check (147 packages loaded, 814 targets configured)

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

Analyzing: target //:license-check (164 packages loaded, 6795 targets configured)

Analyzing: target //:license-check (168 packages loaded, 9844 targets configured)

Analyzing: target //:license-check (168 packages loaded, 9844 targets configured)

Analyzing: target //:license-check (168 packages loaded, 9844 targets configured)

Analyzing: target //:license-check (172 packages loaded, 14061 targets configured)

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

INFO: Analyzed target //:license-check (176 packages loaded, 16077 targets configured).
[11 / 16] [Prepa] JavaToolchainCompileClasses external/rules_java+/toolchains/platformclasspath_classes ... (2 actions, 0 running)
INFO: From Generating Dash formatted dependency file ...:
INFO: Successfully converted 50 packages from Cargo.lock to bazel-out/k8-fastbuild/bin/formatted.txt
[14 / 16] [Prepa] JavaToolchainCompileBootClasspath external/rules_java+/toolchains/platformclasspath.jar
[15 / 16] Building license.check.license_check.jar (); 0s disk-cache, multiplex-worker
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: 28.693s, Critical Path: 3.14s
INFO: 16 processes: 12 internal, 3 processwrapper-sandbox, 1 worker.
INFO: Build completed successfully, 16 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 42 items.
[main] INFO Found 32 items.
[main] INFO Querying ClearlyDefined for license data for 10 items.
[main] INFO HTTP response 502 (Bad Gateway). Trying again...
[main] INFO Found 10 items.
[main] INFO License information could not be automatically verified for the following content:
[main] INFO 
[main] INFO crate/cratesio/-/lazy_static/1.5.1
[main] INFO 
[main] INFO This content is either not correctly mapped by the system, or requires review.

@github-actions

Copy link
Copy Markdown
Contributor

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
@atarekra
atarekra deployed to workflow-approval July 14, 2026 16:00 — with GitHub Actions Active
@atarekra
atarekra deployed to workflow-approval July 14, 2026 16:00 — with GitHub Actions Active
@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
Contributor

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
@atarekra
atarekra deployed to workflow-approval August 30, 2026 08:48 — with GitHub Actions Active
@atarekra
atarekra deployed to workflow-approval August 30, 2026 08:48 — with GitHub Actions Active
@github-actions github-actions Bot removed the stale label Aug 31, 2026
arkjedrz
arkjedrz previously approved these changes Sep 1, 2026
Comment thread score/kvs/kvs.cpp
@@ -432,6 +457,14 @@ score::Result<bool> Kvs::is_value_default(const std::string_view key) const
/* Set the value for a key*/
score::ResultBlank Kvs::set_value(const std::string_view key, const KvsValue& value)
{

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.

why did not you validate also in get_value function ?

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.

set_value is where the limit is actually enforced , an over-length key can never get into the map, so lookups fail anyway. But the error is misleading: you get KeyNotFound when the real problem is an invalid key.

Comment thread score/kvs/kvs.cpp
{
logger->LogError() << "Key length" << key.length() << "exceeds maximum allowed"
<< KVS_MAX_KEY_LENGTH_BYTES << "bytes while loading";
result = score::MakeUnexpected(ErrorCode::KeyTooLong);

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.

i would suggest her to return ErrorCode::KvsFileReadError with logging key string and key length

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.

Agreed on logging the key that's missing and should be there.

On the code: KvsFileReadError means the file couldn't be read, but here it read and parsed fine and the checksum was valid , it's the content that breaks a rule. ValidationFailed is what we already return for a bad checksum, so it may fit better, and it keeps KeyTooLong (new in this PR) meaning purely "the key you passed is invalid". What do you think?

@atarekra
atarekra deployed to workflow-approval October 4, 2026 14:43 — with GitHub Actions Active
@atarekra
atarekra deployed to workflow-approval October 4, 2026 14:43 — with GitHub Actions Active
arkjedrz
arkjedrz previously approved these changes Oct 5, 2026

@Ahmed-Elsaka-JC Ahmed-Elsaka-JC 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.

LGFM

@Ahmed-Elsaka-JC
Ahmed-Elsaka-JC self-requested a review October 7, 2026 08:19
@atarekra
atarekra force-pushed the Max-KeyLength-Feature branch from 818b207 to e4316fe Compare October 12, 2026 09:32
@atarekra
atarekra deployed to workflow-approval October 12, 2026 09:32 — with GitHub Actions Active
@atarekra
atarekra deployed to workflow-approval October 12, 2026 09:32 — with GitHub Actions Active
arkjedrz
arkjedrz previously approved these changes Oct 12, 2026
PandaeDo
PandaeDo previously approved these changes Oct 12, 2026
@PandaeDo
PandaeDo added this pull request to the merge queue Oct 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 12, 2026
Implement comp_req__kvs__key_length. Keys longer than
KVS_MAX_KEY_LENGTH_BYTES (32) are rejected with the new
ErrorCode::KeyTooLong:

- set_value() refuses to store them.
- get_value() reports KeyTooLong rather than KeyNotFound, since such a
  key can never have been stored.
- Loading a file that contains one halts with KeyTooLong rather than
  silently dropping the entry.

All three log the offending key and its length. The rule lives in one
helper, is_key_length_valid(), shared by every path that reads a key.

Signed-off-by: atarekra <ahmed.tarek-ramadan@valeo.com>
@atarekra
atarekra dismissed stale reviews from PandaeDo and arkjedrz via 0c329e8 October 12, 2026 10:58
@atarekra
atarekra force-pushed the Max-KeyLength-Feature branch from e4316fe to 0c329e8 Compare October 12, 2026 10:58
@atarekra
atarekra deployed to workflow-approval October 12, 2026 10:58 — with GitHub Actions Active
@atarekra
atarekra deployed to workflow-approval October 12, 2026 10:58 — with GitHub Actions Active
@PandaeDo
PandaeDo added this pull request to the merge queue Oct 12, 2026
Merged via the queue into eclipse-score:main with commit f272d48 Oct 12, 2026
23 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in PER - Persistency FT Oct 12, 2026

This branch was successfully deployed

1 active deployment
workflow-approval — 0c329e89 Deployed Oct 12, 2026 by atarekra via qnx-build (per-x86_64-qnx) / approval #769
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants