From 60f0f64b57c0a0d146fc0b51989a894065b16ca0 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 11 Aug 2023 19:36:26 +0200 Subject: [PATCH] (Windows) Fixed an issue where the media viewer could crash if attempting to display corrupt or invalid PDF game manuals --- es-app/src/PDFViewer.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/es-app/src/PDFViewer.cpp b/es-app/src/PDFViewer.cpp index c4f3799da..ed933d44b 100644 --- a/es-app/src/PDFViewer.cpp +++ b/es-app/src/PDFViewer.cpp @@ -244,9 +244,6 @@ bool PDFViewer::getDocumentInfo() return false; } - // Close process and thread handles. - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); CloseHandle(childStdoutWrite); std::array buffer {}; @@ -268,6 +265,18 @@ bool PDFViewer::getDocumentInfo() CloseHandle(childStdoutRead); WaitForSingleObject(pi.hThread, INFINITE); WaitForSingleObject(pi.hProcess, INFINITE); + + DWORD exitCode {0}; + if (GetExitCodeProcess(pi.hProcess, &exitCode) && exitCode != 0) { + LOG(LogError) << "Couldn't read PDF document information"; + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + return false; + } + + // Close process and thread handles. + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); #else FILE* commandPipe; std::array buffer {};