mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Reject sizes past the end of the state before allocating (FPL, PGF, achievements, SAS grain, savedata list, the memory fast path), fail instead of desyncing on a SAS voice count mismatch, and free what old states' paths and shrinking pointer containers dropped. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
#pragma once
|
|
|
|
// Templates for save state serialization. See Serializer.h.
|
|
#include <deque>
|
|
#include "Common/Serialize/SerializeFuncs.h"
|
|
|
|
template<class T>
|
|
void DoDeque(PointerWrap &p, std::deque<T> &x, T &default_val) {
|
|
u32 deq_size = (u32)x.size();
|
|
Do(p, deq_size);
|
|
// Guard against an attacker-controlled size driving a huge resize, same as DoVector.
|
|
if (p.mode == PointerWrap::MODE_READ || p.mode == PointerWrap::MODE_VERIFY) {
|
|
if (deq_size > p.Remaining() / SerializeMinElemSize<T>()) {
|
|
p.SetError(PointerWrap::ERROR_FAILURE);
|
|
return;
|
|
}
|
|
}
|
|
x.resize(deq_size, default_val);
|
|
u32 i;
|
|
for (i = 0; i < deq_size; i++)
|
|
Do(p, x[i]);
|
|
}
|
|
|
|
template<class T>
|
|
void Do(PointerWrap &p, std::deque<T *> &x) {
|
|
if (p.mode == PointerWrap::MODE_READ) {
|
|
// The elements are owned (DoClass replaces them), and a shorter deque would drop the rest.
|
|
for (T *elem : x) {
|
|
delete elem;
|
|
}
|
|
x.clear();
|
|
}
|
|
T *dv = nullptr;
|
|
DoDeque(p, x, dv);
|
|
}
|
|
|
|
template<class T>
|
|
void Do(PointerWrap &p, std::deque<T> &x) {
|
|
T dv = T();
|
|
DoDeque(p, x, dv);
|
|
}
|