فهرست منبع

Merge pull request #371 from marquezinii/fix/pls-path-small-buffer

Storage: a path buffer too small fails with E_FAIL, as on Xbox
Marvis 3 روز پیش
والد
کامیت
40b7ed1add
1فایلهای تغییر یافته به همراه6 افزوده شده و 0 حذف شده
  1. 6 0
      crates/victory-hle/src/modules/storage.rs

+ 6 - 0
crates/victory-hle/src/modules/storage.rs

@@ -38,6 +38,8 @@ pub const IID_2026: Guid = Guid::new(
 pub static OBJECT: Object = Object::new("persistent local storage", &VTABLE);
 pub const INTERFACES: &[Interface] = &[(PROVIDER, IID, &OBJECT), (PROVIDER, IID_2026, &OBJECT)];
 
+const E_FAIL: HRESULT = 0x8000_4005_u32 as i32;
+
 type This = *const Object;
 
 /// The path titles get: the root of a virtual drive over the folder. On the
@@ -63,8 +65,11 @@ extern "system" fn path_size(_: This, out: *mut usize) -> HRESULT {
     }
 }
 
+/// A buffer too small for the path fails with `E_FAIL`, the documented
+/// Xbox result (a PC gets `ERROR_INSUFFICIENT_BUFFER`).
 extern "system" fn path(_: This, size: usize, buffer: *mut u8, used: *mut usize) -> HRESULT {
     match folder() {
+        Some(path) if size <= path.len() => E_FAIL,
         Some(path) => put_string(&path, size, buffer, used),
         None => NOT_SUPPORTED,
     }
@@ -196,6 +201,7 @@ mod tests {
         let (mut buffer, mut used) = ([0u8; 4], 0);
         let get = method::<Get>(&OBJECT, 0x20);
         assert_eq!(get(this, 4, buffer.as_mut_ptr(), &mut used), S_OK);
+        assert_eq!(get(this, 3, buffer.as_mut_ptr(), &mut used), E_FAIL);
         let drive = std::str::from_utf8(&buffer[..3]).unwrap();
         assert!(drive.ends_with(":\\"), "{drive}");
         // Title file calls on it reach the folder.