Skip to content

Commit c1f3b32

Browse files
src/fs: don't attempt zero-byte reads
Sometimes we'll encounter empty files when creating images. Don't attempt to read them: it causes the spare_capacity() helper for the rustix Buffer API to panic. Signed-off-by: Allison Karlitskaya <[email protected]>
1 parent 1ebdad3 commit c1f3b32

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/fs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ impl<ObjectID: FsVerityHashValue> FilesystemReader<'_, ObjectID> {
203203
FileType::Directory | FileType::Unknown => unreachable!(),
204204
FileType::RegularFile => {
205205
let mut buffer = Vec::with_capacity(buf.st_size as usize);
206-
read(fd, spare_capacity(&mut buffer))?;
206+
if buf.st_size > 0 {
207+
read(fd, spare_capacity(&mut buffer))?;
208+
}
207209
let buffer = Box::from(buffer);
208210

209211
if buf.st_size > INLINE_CONTENT_MAX as i64 {

0 commit comments

Comments
 (0)