From fd4ebb95b727df165ec8d2f525bb9ad65f47ba6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=8C=E5=AD=90=E5=8F=B6=E6=A4=8D=E7=89=A9?= <149964080+Dicot0721@users.noreply.github.com> Date: Thu, 30 Oct 2025 22:07:05 +0800 Subject: [PATCH] modules/SceCommonDialog: Fix 'check_save_file' crash on Linux (#3664) - When `iconPath` is empty string, `vfs::read_file` will try to open dictory `ux0` as a binary file to read, which have no effect on Windows but crash on *nix (Linux/Android/...). - `std::ifstream` can open a directory as file on *nix (but can not on Windows), and after that `std::ifstream::tellg()` return the max value that the return type can represent (strangely not fail), which leads to throwing an exception when buffer is being resized. --- vita3k/modules/SceCommonDialog/SceCommonDialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vita3k/modules/SceCommonDialog/SceCommonDialog.cpp b/vita3k/modules/SceCommonDialog/SceCommonDialog.cpp index fab9c1db1..060e9ca7f 100644 --- a/vita3k/modules/SceCommonDialog/SceCommonDialog.cpp +++ b/vita3k/modules/SceCommonDialog/SceCommonDialog.cpp @@ -825,10 +825,10 @@ static void check_save_file(const uint32_t index, EmuEnvState &emuenv, const cha auto empty_param = emuenv.common_dialog.savedata.list_empty_param[index]; if (empty_param) { emuenv.common_dialog.savedata.title[index] = empty_param->title ? empty_param->title.get(emuenv.mem) : emuenv.common_dialog.lang.save_data.save["new_saved_data"]; - const auto iconPath = empty_param->iconPath.get(emuenv.mem); + const char *iconPath = empty_param->iconPath.get(emuenv.mem); SceUChar8 *iconBuf = empty_param->iconBuf.cast().get(emuenv.mem); const auto iconBufSize = empty_param->iconBufSize; - if (iconPath) { + if (iconPath && (std::strlen(iconPath) > 0)) { auto device = device::get_device(iconPath); const auto thumbnail_path = translate_path(empty_param->iconPath.get(emuenv.mem), device, emuenv.io.device_paths); vfs::read_file(VitaIoDevice::ux0, icon_buf_tmp, emuenv.pref_path, thumbnail_path);