Initialise the internal buffer before handing it to the reader - #10
Open
icedracon wants to merge 1 commit into
Open
Initialise the internal buffer before handing it to the reader#10icedracon wants to merge 1 commit into
icedracon wants to merge 1 commit into
Conversation
`with_capacity` called `set_len` on a `Vec` that was never written to, and `fill_buf` passes that buffer straight to the wrapped `Read` impl. Since `Read::read` only recommends against reading `buf` rather than forbidding it, an implementation that inspects its buffer observed uninitialised memory, which Miri reports as undefined behaviour. Allocate a zeroed buffer instead. This also drops the `read_initializer` call, whose nightly feature gate no longer exists in the compiler, so that path could not be enabled on any current toolchain anyway. Adds a regression test that fails under Miri if the buffer is left uninitialised. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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 #9.
with_capacitycalledset_lenon aVecthat was never written to, andfill_bufpasses that buffer straight to the wrappedReadimpl.Read::readonly recommends against readingbufrather than forbidding it, so an implementation that inspects its buffer observed uninitialised memory.Miri on the current release:
Change
Allocate a zeroed buffer instead:
std::io::BufReadershipped exactly this for years before moving toBorrowedBuf/read_buf.This also drops the
inner.initializer().initialize(&mut buffer)call. That path sat behindfeature = "read_initializer", which needs the#![feature(read_initializer)]nightly gate — a language feature that has since been removed from the compiler, so it could not be enabled on any current toolchain. Theread_initializerfeature flag itself and theRead::initializerimpl are left alone; removing them is a separate cleanup if you want it.Verification
test_buffer_handed_to_reader_is_initializedcargo +nightly miri testclean on the patched crateHappy to adjust anything.