authfs: fix crash on read_chunk of a remote file
testReadWithFsverityVerification_RemoteSmallerFile was actually broken
by the previous change (aosp/1647309). I might have had tested my
previous change against the unchanged executable in the apex.
Bug: 182173887
Test: atest
Change-Id: I42c21894460c427f11d104927e25bea4ec98ef5e
diff --git a/authfs/src/file/remote_file.rs b/authfs/src/file/remote_file.rs
index f2ac23f..9d614f5 100644
--- a/authfs/src/file/remote_file.rs
+++ b/authfs/src/file/remote_file.rs
@@ -41,8 +41,9 @@
.unwrap()
.readFile(remote_fd, offset, buf.len() as i32)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.get_description()))?;
- buf.copy_from_slice(&chunk);
- Ok(min(buf.len(), chunk.len()))
+ let size = min(buf.len(), chunk.len());
+ buf[..size].copy_from_slice(&chunk[..size]);
+ Ok(size)
}
pub struct RemoteFileReader {
@@ -87,8 +88,9 @@
.unwrap()
.readFsverityMerkleTree(self.file_fd, offset, buf.len() as i32)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.get_description()))?;
- buf.copy_from_slice(&chunk);
- Ok(min(buf.len(), chunk.len()))
+ let size = min(buf.len(), chunk.len());
+ buf[..size].copy_from_slice(&chunk[..size]);
+ Ok(size)
}
}