fs: fill the destination buffer with 0s for MockFile::read() (#7596)

This commit is contained in:
Martin Grigorov 2025-09-10 11:41:20 +03:00 committed by GitHub
parent 510b9ea9dc
commit 94b6df699b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -56,6 +56,13 @@ mock! {
impl Read for MockFile { impl Read for MockFile {
fn read(&mut self, dst: &mut [u8]) -> io::Result<usize> { fn read(&mut self, dst: &mut [u8]) -> io::Result<usize> {
// Placate Miri. Tokio will call this method with an uninitialized
// buffer, which is ok because std::io::Read::read implementations don't usually read
// from their input buffers. But Mockall 0.12-0.13 will try to Debug::fmt the
// buffer, even if there is no failure, triggering an uninitialized data access alert from
// Miri. Initialize the data here just to prevent those Miri alerts.
// This can be removed after upgrading to Mockall 0.14.
dst.fill(0);
self.inner_read(dst) self.inner_read(dst)
} }
} }