补充 Windows 原子替换安全说明
记录 MoveFileExW 路径缓冲区的所有权、终止符和调用生命周期不变量。
This commit is contained in:
+3
-1
@@ -141,7 +141,7 @@ fn replace_separation_state_atomically(temporary: &Path, target: &Path) -> std::
|
||||
fn replace_separation_state_atomically(temporary: &Path, target: &Path) -> std::io::Result<()> {
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use windows_sys::Win32::Storage::FileSystem::{
|
||||
MOVEFILE_REPLACE_EXISTING, MOVEFILE_WRITE_THROUGH, MoveFileExW,
|
||||
MoveFileExW, MOVEFILE_REPLACE_EXISTING, MOVEFILE_WRITE_THROUGH,
|
||||
};
|
||||
|
||||
let source = temporary
|
||||
@@ -154,6 +154,8 @@ fn replace_separation_state_atomically(temporary: &Path, target: &Path) -> std::
|
||||
.encode_wide()
|
||||
.chain(std::iter::once(0))
|
||||
.collect::<Vec<_>>();
|
||||
// SAFETY: both buffers are owned, UTF-16 encoded, and NUL-terminated; they
|
||||
// remain alive for the duration of the call, which only reads the paths.
|
||||
let moved = unsafe {
|
||||
MoveFileExW(
|
||||
source.as_ptr(),
|
||||
|
||||
Reference in New Issue
Block a user