Repository navigation
Conversation
In BlobCopier::copy_fast and BlobCopier::copy, blob offsets and lengths from index locations were subtracted and sliced directly from data/read_data without checking that blob.offset >= offset or that blob.offset + blob.length <= offset + data.len(). A corrupted or malformed index entry could trigger an underflow/overflow panic or an out-of-bounds slice panic, terminating the process during repack/copy. Add get_blob_slice with checked arithmetic and bounds verification that returns a descriptive RusticError (ErrorKind::Repository) instead of panicking. Reported-by: BS.ehlas.cz
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
In
BlobCopier::copy_fastandBlobCopier::copy(crates/core/src/blob/packer.rs), blob slice offsets are computed directly from index locations:If an index file contains malformed or corrupted metadata where:
blob.offset < offset(causing unsigned subtraction underflow / panic),blob.offset + blob.lengthoverflowsu32, orstartorendexceedsdata.len()/read_data.len(),the process panics with
.expect(...)or out-of-bounds slice indexing&data[start..end], crashing any host application performing repo prune, repack, or copy operations.Fix
get_blob_slicethat useschecked_sub,checked_add, and safe slice lookupdata.get(start..end).copy_fastandcopywith calls toget_blob_slice.RusticError(ErrorKind::Repository) with diagnostic context (blob_id,pack_id,blob_offset,blob_length,read_offset,read_length) instead of crashing.Tests
test_get_blob_sliceverifying normal slices, base offsets, underflow (blob.offset < offset), overflow (blob.offset + length > u32::MAX), and out-of-bounds access.cargo test -p rustic_core --lib -- blob::packer::tests).cargo test -p rustic_core --test integration -- prune,cargo test -p rustic_core --test integration -- copy).Disclaimer: Found the issue by test-driving an LM-powered vulnerability scanner I work on heavily.