Skip to content

Commit 6f94ace

Browse files
committed
truncate backing file path exceeding 64 bytes in LoopInfo
When the backing file path exceeds 64 bytes, an 'out of range' error occurs due to the limitation of the `file_name` field in `LoopInfo`. This commit truncates the file path to ensure it does not exceed the maximum supported length, preventing the error while maintaining usability.
1 parent afab3c8 commit 6f94ace

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crates/shim/src/mount_linux.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,8 @@ pub fn setup_loop_dev(backing_file: &str, loop_dev: &str, params: &LoopParams) -
791791
}
792792
// 3. set info
793793
let mut info = LoopInfo::default();
794-
info.file_name[..backing_file.as_bytes().len()].copy_from_slice(backing_file.as_bytes());
794+
let backing_file_truncated = if backing_file.as_bytes().len() > info.file_name.len() { &backing_file[0..info.file_name.len()] } else { backing_file };
795+
info.file_name[..backing_file_truncated.as_bytes().len()].copy_from_slice(backing_file_truncated.as_bytes());
795796
if params.readonly {
796797
info.flags |= LO_FLAGS_READ_ONLY;
797798
}

0 commit comments

Comments
 (0)