fix: include segments_count bytes in worst_case_body_size (M8)#565
Conversation
worst_case_body_size was missing the size_of::<usize>() bytes from segments_count.to_ne_bytes() that build_prefix_body appends. On 64-bit platforms this underestimates by 8 bytes, causing paths with body sizes in [57,64] to estimate 1 Blake3 block when 2 are actually needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #565 +/- ##
===========================================
- Coverage 90.66% 90.66% -0.01%
===========================================
Files 182 182
Lines 49474 49491 +17
===========================================
+ Hits 44856 44869 +13
- Misses 4618 4622 +4
🚀 New features to boost your workflow:
|
Summary
Fixes audit finding M8:
worst_case_body_sizeunderestimates prefix hash input by 8 bytes (on 64-bit platforms).Problem
build_prefix_bodyconstructs a body consisting of:segments_count.to_ne_bytes()— ausize(8 bytes on 64-bit)u8length byte per segmentBut
worst_case_body_sizeonly accounted for #1 and #3:This underestimate means a path with body size in [57, 64] would be estimated as needing 1 Blake3 block (≤64 bytes) when it actually requires 2 blocks (>64 bytes), causing fee cost estimation to undercharge.
Fix
Add
std::mem::size_of::<usize>()to the computation:Test plan
cargo test -p grovedb-storage)cargo test -p grovedb --lib)🤖 Generated with Claude Code