Skip to content

Commit 0e4ff0c

Browse files
lujindamxpv
authored andcommitted
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. Signed-off-by: jinda.ljd <[email protected]>
1 parent afab3c8 commit 0e4ff0c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

crates/shim/src/mount_linux.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,13 @@ 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() {
795+
&backing_file[0..info.file_name.len()]
796+
} else {
797+
backing_file
798+
};
799+
info.file_name[..backing_file_truncated.as_bytes().len()]
800+
.copy_from_slice(backing_file_truncated.as_bytes());
795801
if params.readonly {
796802
info.flags |= LO_FLAGS_READ_ONLY;
797803
}

0 commit comments

Comments
 (0)