Skip to content

Commit 1c2c62f

Browse files
committed
Bound PKG entry table allocation
PKG file_count was used for vector allocation before validating that the encrypted package data contained the entry table. Limit the count and require the entry table to fit in the declared data region before allocating.
1 parent 2f31d26 commit 1c2c62f

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

rpcs3/Crypto/unpkg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ bool package_reader::read_header()
121121
return false;
122122
}
123123

124-
if (u64{umax} / sizeof(PKGEntry) < u64(m_header.file_count))
124+
if (m_header.file_count > PKG_MAX_FILE_COUNT || u64(m_header.file_count) > u64(m_header.data_size) / sizeof(PKGEntry))
125125
{
126-
pkg_log.error("PKG file count is too large! (0x%x)", m_header.file_count);
126+
pkg_log.error("PKG file count is invalid! (count=0x%x, data_size=0x%llx)", m_header.file_count, m_header.data_size);
127127
return false;
128128
}
129129

rpcs3/Crypto/unpkg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum : u32
1414
{
1515
PKG_HEADER_SIZE = 0xC0, // sizeof(pkg_header) + sizeof(pkg_unk_checksum)
1616
PKG_HEADER_SIZE2 = 0x280,
17+
PKG_MAX_FILE_COUNT = 1'000'000,
1718
PKG_MAX_FILENAME_SIZE = 256,
1819
};
1920

0 commit comments

Comments
 (0)