From ab8803078404dd8c11cf0d3441ff3a86b6bda22b Mon Sep 17 00:00:00 2001 From: Dipal Date: Fri, 20 Nov 2026 11:30:58 -0500 Subject: [PATCH] Fail to open a .rpv with non-string compare_files entries instead of aborting --- src/app/test/app_tests.cpp | 37 +++++++++++++++++++++++++++++ src/view/src/rocprofvis_project.cpp | 18 +++++++++++--- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/app/test/app_tests.cpp b/src/app/test/app_tests.cpp index 18cfc4487..abb58864e 100644 --- a/src/app/test/app_tests.cpp +++ b/src/app/test/app_tests.cpp @@ -2963,6 +2963,43 @@ void RegisterAppTests(ImGuiTestEngine* e) IM_CHECK(still_missing); }; + // AIPROFVIS-703: a .rpv whose compare_files holds a non-string entry used to abort + // the app inside jt::Json::getString(). It must fail as a corrupted project. + t = IM_REGISTER_TEST(e, "app", "sys_project_malformed_compare_files_error"); + t->TestFunc = [](ImGuiTestContext* ctx) + { + namespace fs = std::filesystem; + + AppWindow* app = AppWindow::GetInstance(); + IM_CHECK(app != nullptr); + if (app == nullptr) return; + + const fs::path rpv_path = + fs::temp_directory_path() / "rocprofvis_malformed_compare_files.rpv"; + { + std::ofstream out(rpv_path); + IM_CHECK(out.is_open()); + if (!out.is_open()) return; + out << "{\"general\": {\"version\": \"1.0\", \"compare_files\": [1, 2]}}"; + } + + Project proj; + std::string path = rpv_path.string(); + const Project::OpenResult result = proj.Open(path); + const std::string message = ProjectTestPeer{proj}.OpenErrorMessage(); + + std::error_code ec; + fs::remove(rpv_path, ec); + + // Close the queued error dialog so it doesn't block later tests. + ctx->Yield(2); + ctx->PopupCloseAll(); + ctx->Yield(2); + + IM_CHECK(result == Project::OpenResult::Failed); + IM_CHECK(message.find("invalid or corrupted") != std::string::npos); + }; + // AIPROFVIS-81: Event Details dropped the argument list for HIP API events. // Presence/shape only -- the args come back asynchronously through the // controller, with no single table to build a value oracle from. diff --git a/src/view/src/rocprofvis_project.cpp b/src/view/src/rocprofvis_project.cpp index 9d8f3bd36..135c858f5 100644 --- a/src/view/src/rocprofvis_project.cpp +++ b/src/view/src/rocprofvis_project.cpp @@ -362,9 +362,21 @@ Project::OpenCompare(const std::string& project_id, bool Project::JsonValidForLoad(jt::Json& json) { - jt::Json& general = json[JSON_KEY_GROUP_GENERAL]; - return general[JSON_KEY_GENERAL_TRACE_PATH].isString() || - general[JSON_KEY_GENERAL_COMPARE_FILES].isArray(); + jt::Json& general = json[JSON_KEY_GROUP_GENERAL]; + jt::Json& compare_files = general[JSON_KEY_GENERAL_COMPARE_FILES]; + if(compare_files.isArray()) + { + // jt getters abort on a type mismatch, so reject non-string entries here. + for(jt::Json& entry : compare_files.getArray()) + { + if(!entry.isString()) + { + return false; + } + } + return true; + } + return general[JSON_KEY_GENERAL_TRACE_PATH].isString(); } void