Display: Don't read past memory presenting a framebuffer from RAM

The PSP accepts display strides that run past the end of VRAM, and
negative ones (setframebuf.expected has -64 and 2048), and presenting
straight from memory read all 272 rows of whatever stride was set.
Without a matching framebuffer, that's a read far outside PSP memory.
Now the whole image has to be in memory, or the display shows black, on
the hardware backends and the software renderer.

A savestate's display framebuffer with an address outside RAM and VRAM,
or an invalid format, turns the display off instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-10-19 20:54:29 +02:00
1 parent ef8961e17a
commit fa3eff96fb
3 files changed
+30 -3

No files matched your search

+15
View File
@@ -237,6 +237,17 @@ struct GPUStatistics_v0 {
int moreInts[15];
};
// A savestate's display framebuffer, straight from the file. The stride can be anything (the PSP
// takes negative ones, and GE dump playback sets others): presenting checks that.
static void SanitizeLoadedFramebuf(FrameBufferState &fb) {
const bool validAddr = fb.topaddr == 0 || Memory::IsRAMAddress(fb.topaddr) || Memory::IsVRAMAddress(fb.topaddr);
if (!validAddr || fb.fmt < GE_FORMAT_565 || fb.fmt > GE_FORMAT_8888) {
ERROR_LOG(Log::SaveState, "Savestate has an invalid display framebuffer (%08x, format %d), turning the display off", fb.topaddr, (int)fb.fmt);
fb.topaddr = 0;
fb.fmt = GE_FORMAT_8888;
}
}
void __DisplayDoState(PointerWrap &p) {
auto s = p.Section("sceDisplay", 1, 8);
if (!s)
@@ -244,6 +255,10 @@ void __DisplayDoState(PointerWrap &p) {
Do(p, framebuf);
Do(p, latchedFramebuf);
if (p.mode == p.MODE_READ) {
SanitizeLoadedFramebuf(framebuf);
SanitizeLoadedFramebuf(latchedFramebuf);
}
Do(p, framebufIsLatched);
DisplayHWDoState(p, s <= 2);
Do(p, hasSetMode);