Repository navigation
Clear a partly kept counter behind the end of a temporary file - #301
Merged
Merged
Conversation
With a chunk size that is not a multiple of 8, a truncate can keep only a part of the counter value in front of the block behind the new end. mcTempDropTail() cleared a counter only if all 8 bytes were kept, so a block that a later write left out read as keystream instead of zeros. tempfiletest checks this once with a chunk size that keeps half of the counter of the second block.
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.
mcTempDropTail() clears the counter value of every block that a truncate keeps behind the end of a temporary file, but only if all 8 bytes of the counter are kept. With a chunk size that is not a multiple of 8, the rounded truncate can keep only a part of the counter of the next block. That part survives, and when a later write leaves the block out, the block reads as keystream instead of zeros. Now every block whose counter starts before the physical end is cleared. Writing the 8 zero bytes extends the file by at most 7 bytes, which belong to a zero counter.
SQLite itself sets a chunk size only for sorter files (4096), which does not trigger this; it takes an application that sets such a chunk size for a temporary file.
tempfiletest checks this once at the start: with a chunk size of 4108, a truncate to one block keeps half of the counter of the second block, and after a write to the third block the second one must read as zeros. The check runs on the VFS below the spy, because the spy itself sits on the Multiple Ciphers VFS, so the chunk size of the file under test does not reach the file on disk.
Testing (macOS arm64, flags from Makefile.am):