Merge pull request #88 from AndyLatimer/fix/title-size-overflows

Audio, watch: no overflow on huge title sizes (XMA read advance, fread)
This commit is contained in:
Marvis authored and GitHub committed 2026-11-24 09:47:09 +01:00
commit 8ec67d6288
2 files changed
+22 -3

No files matched your search

+13 -2
View File
@@ -210,7 +210,8 @@ fn open(g: &mut Guards, start: usize, end: usize) -> bool {
/// The runtime calls it (as `kernel_will_write`) before the title's kernel
/// reads into its own memory.
pub fn writing(at: usize, len: usize) {
open(&mut guards(), at, at + len);
// The length is the title's (`fread`'s size times count, saturated).
open(&mut guards(), at, at.saturating_add(len));
}
/// The runtime mapped or unmapped title memory `[at, at + len)`: what it
@@ -219,7 +220,7 @@ pub fn title_memory_remapped(at: usize, len: usize) {
let mut g = guards();
let blocks: Vec<usize> = g
.protected
.range(at / BLOCK..(at + len).div_ceil(BLOCK))
.range(at / BLOCK..at.saturating_add(len).div_ceil(BLOCK))
.copied()
.collect();
for block in blocks {
@@ -367,4 +368,14 @@ mod tests {
unsafe { UnmapViewOfFile(windows_sys::Win32::System::Memory::MEMORY_MAPPED_VIEW_ADDRESS { Value: view as *mut _ }) };
title_memory_remapped(view, 2 * BLOCK);
}
/// A write or mapping that runs past the end of the address space (a
/// title's `fread` with a huge count) covers up to the end; the sum used
/// to overflow. Up there no test has guarded blocks.
#[test]
fn ranges_past_the_address_space_end_do_not_overflow() {
let top = usize::MAX - 16;
writing(top, PAGE);
title_memory_remapped(top, usize::MAX);
}
}