Repository navigation
Bound HEAD reads, refuse generation overflow, and tighten hex and temp-file handling - #23
Merged
Merged
Conversation
…p-file handling - Directory-backend HEAD reads went through read_to_end after a size check, so a FIFO as HEAD blocked forever and a symlink to /dev/zero could exhaust memory. Every directory HEAD read now goes through read_bounded_head_file, which refuses non-regular files and reads at most MAX + 1 bytes, failing with BudgetExhausted beyond MAX. - Manifest and policy generation increments used plain + 1 on storage-controlled values and panicked in debug builds at u64::MAX. They now use checked_add, so overflow is an ordinary validation error. - validate_root and validate_id said lowercase hex but accepted uppercase. Both now accept only 0-9a-f. - A failed directory HEAD write, or README/FORMAT write, left its .HEAD-* temporary behind. Every error path after the temporary exists removes it.
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.
Fixes C2, C5 and C8 from the implementation review. Each was reproduced with a failing test before the fix.
read_bounded_head_filechecked the file size but then used an unboundedread_to_end. Two directory-backend reads (FilesystemStorage::read_headandcompare_and_swap_observed_head) skipped it entirely.take(MAX + 1)and returnsBudgetExhaustedaboveMAX. Every directory HEAD read, including the CAS path, now goes through it.generation + 1on storage-controlled values panicked in debug builds atu64::MAX.manifest.rs:108andpolicy.rs:128.checked_add, so overflow is an ordinary validation error.PolicyState::successorreports "policy generation overflow". Three local increments inrepository.rswere converted too.validate_rootandvalidate_idsaid lowercase but accepted uppercase. Both now accept only0-9a-f..HEAD-*behind. This was reproduced by making HEAD a non-empty directory so the rename fails. Every error after the temporary exists now removes it. The same applies towrite_file_durable(README.md and FORMAT).Tests
storage::tests::filesystem_head_reads_refuse_a_fifo(unix; each call runs on a thread with a 5 s timeout)storage::tests::filesystem_head_reads_reject_oversized_headsmanifest::tests::generation_overflow_is_a_validation_errorpolicy::tests::generation_overflow_is_a_validation_errorcrypto::tests::repository_root_must_be_lowercase_hexstorage::tests::object_ids_must_be_lowercase_hexstorage::tests::failed_head_write_removes_its_temporarycargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo test --all-targets(156 passed, with currentmainmerged in).Known limit
If HEAD is swapped for a FIFO between the regular-file check and the open, the open can still block. Closing that needs
O_NONBLOCKfromlibcorrustix. I did not add the dependency. The impact is a hang, not an integrity failure, and it needs someone who can rewrite the storage directory at that moment.