Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/FIFO.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class FIFO
file->Var32(&WritePos);

file->VarArray(Entries, sizeof(T)*NumEntries);

if (!file->Saving && !file->Error &&
(NumOccupied > NumEntries || ReadPos >= NumEntries || WritePos >= NumEntries))
{
file->Error = true;
}
}


Expand Down Expand Up @@ -136,6 +142,12 @@ class DynamicFIFO
file->Var32(&WritePos);

file->VarArray(Entries, sizeof(T)*NumEntries);

if (!file->Saving && !file->Error &&
(NumOccupied > NumEntries || ReadPos >= NumEntries || WritePos >= NumEntries))
{
file->Error = true;
}
}


Expand Down Expand Up @@ -213,6 +225,12 @@ class RingBuffer
file->Var32(&WritePos);

file->VarArray(Buffer, Size);

if (!file->Saving && !file->Error &&
(NumOccupied > Size || ReadPos >= Size || WritePos >= Size))
{
file->Error = true;
}
}


Expand Down
22 changes: 14 additions & 8 deletions src/Savestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ u32 Savestate::FindSection(const char* magic) const
for (u32 offset = 0x10; offset < buffer_length;)
{ // Until we've found the desired section...

if (buffer_length - offset < 16)
{
Log(LogLevel::Error, "savestate: truncated section header\n");
return NO_SECTION;
}

// Get this section's magic number
char read_magic[4] = {0};
memcpy(read_magic, buffer + offset, sizeof(read_magic));
Expand All @@ -378,15 +384,15 @@ u32 Savestate::FindSection(const char* magic) const

// Haven't found our section yet. Let's move on to the next one.

u32 section_length_offset = offset + sizeof(read_magic);
if (section_length_offset >= buffer_length)
{ // If trying to read the section length would take us past the file's end...
break;
}

// First we need to find out how big this section is...
u32 section_length = 0;
memcpy(&section_length, buffer + section_length_offset, sizeof(section_length));
memcpy(&section_length, buffer + offset + sizeof(read_magic), sizeof(section_length));

if (section_length < 16 || section_length > buffer_length - offset)
{
Log(LogLevel::Error, "savestate: invalid section length %u\n", section_length);
return NO_SECTION;
}

// ...then skip it. (The section length includes the 16-byte header.)
offset += section_length;
Expand All @@ -397,4 +403,4 @@ u32 Savestate::FindSection(const char* magic) const
return NO_SECTION;
}

}
}