PSAR: Bound entries by the file size, not the declared size

The last entry's contents can run past the size the header declares (1.x
updaters, and the 4.21 and 5.70 PSARs), so the wraparound check from
c5673294ab refused them. The file size is enough to stop the wrap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-11-06 14:08:58 +01:00
1 parent 004dcdfe93
commit 1908ac5e92
1 file changed
+3 -1
+3 -1
View File
@@ -699,7 +699,9 @@ int PSARReader::NextEntry(std::string *error) {
const u32 chunkSize = ReadU32(block_.data() + 0x104);
const u32 expandedSize = ReadU32(block_.data() + 0x108);
// pos_ is a u32, so a huge chunk would wrap it back to an earlier entry and loop forever.
if (chunkSize > limit_ - std::min((size_t)pos_, limit_)) {
// Check against the file, not limit_: the last entry's contents can run past the size the
// header declares (1.x updaters, and the 3.60, 4.21 and 5.70 PSARs).
if (chunkSize > size_ - std::min((size_t)pos_, size_)) {
*error = StringFromFormat("Entry '%s' runs past the end of the archive (%u bytes)", entryName_.c_str(), chunkSize);
return -1;
}