From f82a37a0f32598846b10b14cee9a7f228d836dd2 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 23 Jan 2023 19:07:08 +0200 Subject: [PATCH] fixed checking for pkg size --- shadPS4/emulator/fileFormat/PKG.cpp | 10 ++++++++++ shadPS4/emulator/fileFormat/PKG.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/shadPS4/emulator/fileFormat/PKG.cpp b/shadPS4/emulator/fileFormat/PKG.cpp index 17b3c8c1..b7b6efca 100644 --- a/shadPS4/emulator/fileFormat/PKG.cpp +++ b/shadPS4/emulator/fileFormat/PKG.cpp @@ -42,6 +42,16 @@ bool PKG::extract(const std::string& filepath, const std::string& extractPath, s PKGHeader pkgheader; file.ReadBE(pkgheader); + if (pkgheader.pkg_size > pkgSize) + { + failreason = "PKG file size is different"; + return false; + } + if ((pkgheader.pkg_content_size + pkgheader.pkg_content_offset) > pkgheader.pkg_size) + { + failreason = "Content size is bigger than pkg size"; + return false; + } file.Seek(0, fsSeekSet); pkg = (U08*)mmap(pkgSize, file.fileDescr()); diff --git a/shadPS4/emulator/fileFormat/PKG.h b/shadPS4/emulator/fileFormat/PKG.h index a2d0afa1..992a38e2 100644 --- a/shadPS4/emulator/fileFormat/PKG.h +++ b/shadPS4/emulator/fileFormat/PKG.h @@ -71,6 +71,9 @@ inline void ReadBE(PKGHeader& s) ReadBE(s.magic); ReadBE(s.pkg_table_entry_offset); ReadBE(s.pkg_table_entry_count); + ReadBE(s.pkg_content_offset); + ReadBE(s.pkg_content_size); + ReadBE(s.pkg_size); } struct PKGEntry {