Repository navigation
fix(tiles): bound a pack scan's record buffer by the file length - #4
Merged
Merged
Conversation
scan reads a record head and resizes its buffer to the path and stored lengths the head declares before reading them, so a crash that leaves a head and nothing after it costs whatever the torn bytes claim, up to 4 GiB per open. The test appends a put head declaring 256 MiB after a good record and counts allocations through a global allocator while open_read scans it: the peak is the declared size where it should stay under 1 MiB.
scan takes the file length when it starts and stops at a head whose declared record would run past it, before the buffer is resized, so a torn head is the end of the valid records it already was without the allocation its lengths claim. A scan runs under the change lock whenever a writer truncates after it, so nothing appended meanwhile is mistaken for a torn tail; a reader picks such records up on its next refresh as before.
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.
Opening or refreshing a
PackStorenow stops at a record head that declares more bytes than the file holds, before sizing a buffer for it.scanread a record head and resized its buffer to the path and stored lengths the head declared before reading them, so a crash that left a head and nothing after it cost whatever the torn bytes claimed, up to 4 GiB per open.scannow takes the file length when it starts and stops at a head whose declared record would run past it, before the buffer is resized. A scan runs under the change lock whenever a writer truncates after it, so nothing appended meanwhile is mistaken for a torn tail.open_readscans it: the peak stays under 1 MiB.The branch has a towncrier fragment.