Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: avoid buffer bleed when reading past the end of the file #1439

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

matklad
Copy link
Member

@matklad matklad commented Jan 18, 2024

bytes_read == 0 is an EOF condition. If we failed to read anything, better to zero out the buffer explicitly, like we do for other failure cases, so that the caller doesn't see "garbage" data that was there before.

This shouldn't matter in practice, as the caller always verifies the checksum anyway, but still feels like a good defense in depth.

`bytes_read == 0` is an EOF condition. If we failed to read anything,
better to zero out the buffer explicitly, like we do for other failure
cases, so that the caller doesn't see "garbage" data that was there
before.

This _shouldn't_ matter in practice, as the caller always verifies the
checksum anyway, but still feels like a good defense in depth.
@matklad
Copy link
Member Author

matklad commented Jan 18, 2024

Found this one live at https://youtu.be/THWDx_RyZ6A!

@@ -299,7 +300,8 @@ pub const Storage = struct {
// - Another replica requested a block, but we are lagging far behind, and the block address
// requested is beyond the end of our data file.
if (bytes_read == 0) {
read.callback(read);
@memset(read.buffer, 0);
self.start_read(read, read.buffer.len);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going through start_read rather then directly invoking callback to have "a single return" from the async loop.

@matklad matklad added this pull request to the merge queue Jan 18, 2024
Merged via the queue into main with commit 91539bd Jan 18, 2024
25 checks passed
@matklad matklad deleted the matklad/nobleed branch January 18, 2024 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants