fix: prevent memory limiter bypass via u32 truncation in Archive::total_size - #19
Open
yasinlex wants to merge 1 commit into
Open
Conversation
…al_size Archive::total_size was stored as u32 and set via silent `as u32` casts in all three constructors (from_ustar, from_zip, from_file_and_runner). Archives exceeding 4 GB silently wrap to a small value, causing limiter.consume() to charge only a tiny amount — the full multi-GB payload is still loaded, bypassing the memory limiter entirely. - Change total_size field type from u32 to u64 - Clamp to u32::MAX at construction sites (.min(u32::MAX as usize)) so archives larger than 4 GB are charged at the maximum, correctly exhausting the budget and returning OOM instead of silently passing - Add explicit as u32 casts at limiter.consume() call sites in cache.rs for clarity (the clamped u64 value always fits in u32)
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughArchive size storage now uses capped ChangesArchive Size Accounting
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Archive::total_sizeis stored asu32and set via silentas u32casts in all three constructors (from_ustar,from_zip,from_file_and_runner). If a runner archive exceeds 4,294,967,295 bytes (~4 GB), theas u32cast silently truncates the value.For example, a 4 GB + 1 byte archive becomes
total_size == 1. Whencache.rscallslimiter.consume(arch.total_size), only 1 byte is charged against the memory budget — the full multi-GB payload is still loaded into theBTreeMap<String, bytes::Bytes>, completely bypassing the memory limiter.This is a denial-of-service vector: an attacker who can supply a runner archive can cause unbounded memory consumption in the executor.
Fix
total_sizefield type fromu32tou64u32::MAXat all construction sites using.min(u32::MAX as usize)— archives larger than 4 GB are charged at the maximum, correctly exhausting the remaining budget and returning OOM instead of silently passingas u32casts atlimiter.consume()call sites incache.rsfor clarity (the clamped u64 value always fits in u32)Files changed
executor/src/runners/ustar.rs: field type u32→u64, 3 construction sites clampedexecutor/src/runners/cache.rs: 2 explicitas u32casts at limiter.consume() call sitesSummary by CodeRabbit