Skip to content

fix(query): refuse an overlong path segment in a ranged aggregate sum query - #1044

Merged
QuantumExplorer merged 2 commits into
developfrom
fix/aggregate-sum-range-overlong-segment
Nov 13, 2026
Merged

QuantumExplorer merged 2 commits into
developfrom
fix/aggregate-sum-range-overlong-segment

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: query_aggregate_sums adds up sum items along a query until a sum limit is reached. When the query item was a range and the caller's path had a segment longer than 255 bytes, the call panicked. It now returns an error, as the same call with a key query item already does.

Value: A caller who passes a bad path gets InvalidInput back instead of a crashed process.

Risks: Very low. One check is added before a storage call that could only panic for the paths the check refuses. No stored data, hash or cost changes.

Issue being fixed or feature implemented

Storage records each path segment length in one byte when it builds a subtree prefix, so a path with a segment longer than 255 bytes panics there. #1006 (for #680) added validate_path_segment_lengths just before each place where a caller's path first reaches prefix construction. The aggregate sum walk has its own copy of the query walk, and its range branch was not covered: it calls get_transactional_storage_context on the caller's path directly.

Keys are capped at 255 bytes on insert, so no subtree has such a path. Only a caller passing one by mistake reaches this.

What was done?

  • aggregate_sum_query_item in grovedb/src/element/aggregate_sum_query/mod.rs calls validate_path_segment_lengths at the start of its range branch, the same line the range branch of the regular query walk has in grovedb/src/element/query.rs.
  • Not gated by grove version: the call the check refuses used to panic under every version.
  • Changelog entry under Unreleased / Fixed.

Before and after

let path = vec![vec![0xAB; 256]];
let query = AggregateSumPathQuery::new_single_query_item(
    path,
    QueryItem::Range(b"a".to_vec()..b"z".to_vec()),
    10,
    None,
);
let result = db.query_aggregate_sums(&query, true, true, None, grove_version).unwrap();
result
Before panic in storage/src/rocksdb_storage/storage.rs ("path segment length must not exceed 255 bytes")
After Err(Error::InvalidInput("path segment length must be at most 255 bytes"))

Unchanged: the same call with a key query item (AggregateSumPathQuery::new_single_key) returned this error before and still does.

Public interface

No signature changes. GroveDb::query_aggregate_sums and GroveDb::query_aggregate_sums_with_options return Error::InvalidInput for a range query over a path with a segment longer than 255 bytes, where they panicked before. Every other input gives the same result as before.

How Has This Been Tested?

grovedb/src/tests/overlong_path_segment_tests.rs gains the entry query_aggregate_sums over a range in the table of path-building calls. The table runs each call at GROVE_V1, GROVE_V3 and the latest grove version, with the overlong segment as the whole path, last under an existing tree, first in a longer path, and in the middle of one. Without the fix every_path_building_call_refuses_an_overlong_segment fails with the storage panic; with it the test passes.

Run locally:

  • cargo test -p grovedb --lib overlong_path_segment (5 passed)
  • cargo test -p grovedb --lib aggregate_sum (149 passed)
  • cargo fmt --all -- --check

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · bde9d54

  • Bots — coderabbitai ✓ · thepastaclaw ✓
  • Self-review — post /self-reviewed
  • Build running
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • Bug Fixes
    • Aggregate-sum range queries with path segments longer than 255 bytes now return an invalid-input error instead of panicking. This behavior applies across supported versions and path shapes. Key-query handling is unchanged.

… query

query_aggregate_sums with a range query item opened the storage context
for the caller's path without checking its segment lengths, so a segment
longer than 255 bytes panicked in storage prefix construction. The key
branch of the same walk and the other path-building calls already return
InvalidInput for such a path (#680, #1006); the range branch of the
aggregate sum walk was the one site left.

Call validate_path_segment_lengths just before the prefix is built, as
the range branch of the regular query walk does. Not version-gated: the
refused call used to panic.

The overlong segment table gains a ranged query_aggregate_sums call, run
at GROVE_V1, GROVE_V3 and latest with the segment alone, last, first and
in the middle.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

query_aggregate_sums validates subtree path segment lengths for range queries before opening the transactional storage context. The overlong-path tests include a range query case, and the changelog records the error returned for an overlong segment. Query::has_subquery now returns its combined condition directly.

Changes: Aggregate sum path validation

Layer / File(s) Summary
Validate range-query paths
grovedb/src/element/aggregate_sum_query/mod.rs, grovedb/src/tests/overlong_path_segment_tests.rs, CHANGELOG.md
Range queries validate subtree path segment lengths before opening the transactional storage context. The overlong-path tests add a query_aggregate_sums range query, and the changelog records the error behavior.

Subquery condition simplification

Layer / File(s) Summary
Return the combined subquery condition
grovedb-query/src/query.rs
Query::has_subquery returns the existing combined condition directly instead of using an explicit conditional.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: shumkov

Merge Risk: Minimal · up to bde9d

Ranged aggregate sum queries with an overlong path segment now return an invalid-input error instead of panicking. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the primary change: a ranged aggregate sum query now refuses an overlong path segment with an error instead of panicking. The changeset matches this. The CHANGELOG entry, the aggregate…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the primary change: a ranged aggregate sum query now refuses an overlong path segment with an error instead of panicking. The changeset matches this. The CHANGELOG entry, the aggregate_sum_query_item validation call, the new overlong-path test case, and the has_subquery refactor all support it. The has_subquery edit is a Clippy fix and does not change the title's main point.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7204cffd-8a27-4906-9372-c7e35c280b8e
Commits

Reviewing files that changed from the base of the PR and between c124e40 and bde9d54.

Files selected for processing: 1

  • grovedb-query/src/query.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 13, 2026
@thepastaclaw

thepastaclaw commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit bde9d54) · triage: low · Phase 2 only (no Phase 1 for this repository)

@thepastaclaw thepastaclaw 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.

Final validation — Phase 2 only (no Phase 1 for this repository)

The change validates aggregate-sum range-query paths before constructing the transactional storage context, preventing the overlong-segment panic while preserving existing behavior for valid inputs. The shared validator, cost-preserving error propagation, version handling, and regression coverage are appropriate; CI code checks are still queued with no reported failures.

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a small, well-contained validation fix in an existing query path with focused regression coverage and no changes to stored data, cryptography, or consensus behavior.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort medium); agent phase2-reviewer

@github-actions

Copy link
Copy Markdown

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 13, 2026
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.21%. Comparing base (3d035d5) to head (bde9d54).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1044      +/-   ##
===========================================
- Coverage    93.32%   93.21%   -0.11%     
===========================================
  Files          366      366              
  Lines       112843   112253     -590     
===========================================
- Hits        105308   104642     -666     
- Misses        7535     7611      +76     
Components Coverage Δ
grovedb-core 91.52% <100.00%> (-0.18%) ⬇️
merk 94.43% <ø> (+0.09%) ⬆️
storage 91.94% <ø> (+0.25%) ⬆️
commitment-tree 94.86% <ø> (-0.77%) ⬇️
mmr 95.12% <ø> (-0.14%) ⬇️
bulk-append-tree 94.32% <ø> (-0.27%) ⬇️
element 97.40% <ø> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

CI installs the floating stable toolchain, which is now Rust 1.100. Its
clippy reports needless_bool for `if cond { return true; } false` in
Query::has_subquery, and the Linting job denies warnings, so every pull
request fails there. Return the condition itself; behaviour is unchanged.

Checked with `cargo +1.100.0 clippy --workspace --exclude grovedb-bincode
--exclude grovedb-bincode-derive --all-features --no-deps -- -D warnings`,
which reports nothing else in the workspace.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 13, 2026

@thepastaclaw thepastaclaw 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.

Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)

The PR correctly adds path-segment validation immediately before the aggregate-sum range query constructs a storage context, converting the prior overlong-segment panic into the established InvalidInput error. The boolean simplification is behaviorally equivalent, regression coverage exercises the relevant path shapes and versions, and all code-related CI checks succeeded.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a small, well-contained validation fix in an existing query path with focused regression coverage and no critical-surface changes.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@github-actions

Copy link
Copy Markdown

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 13, 2026
@QuantumExplorer
QuantumExplorer merged commit d2b0386 into develop Nov 13, 2026
16 of 17 checks passed
@QuantumExplorer
QuantumExplorer deleted the fix/aggregate-sum-range-overlong-segment branch November 13, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants