Merge pull request #9340 from AdmiralCurtiss/truncated-shadercache

Common/LinearDiskCache: Handle truncated shadercache files.
This commit is contained in:
LC 2020-12-19 21:30:40 -05:00 committed by GitHub
commit c08fab6f82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -6,6 +6,7 @@
#include <algorithm>
#include <cstring>
#include <memory>
#include <string>
#include <type_traits>
@ -72,9 +73,10 @@ public:
// good header, read some key/value pairs
K key;
V* value = nullptr;
std::unique_ptr<V[]> value = nullptr;
u32 value_size = 0;
u32 entry_number = 0;
u64 last_valid_value_start = m_file.Tell();
while (m_file.ReadArray(&value_size, 1))
{
@ -82,14 +84,15 @@ public:
if (next_extent > file_size)
break;
delete[] value;
value = new V[value_size];
// TODO: use make_unique_for_overwrite in C++20
value = std::unique_ptr<V[]>(new V[value_size]);
// read key/value and pass to reader
if (m_file.ReadArray(&key, 1) && m_file.ReadArray(value, value_size) &&
if (m_file.ReadArray(&key, 1) && m_file.ReadArray(value.get(), value_size) &&
m_file.ReadArray(&entry_number, 1) && entry_number == m_num_entries + 1)
{
reader.Read(key, value, value_size);
last_valid_value_start = m_file.Tell();
reader.Read(key, value.get(), value_size);
}
else
{
@ -99,8 +102,8 @@ public:
m_num_entries++;
}
m_file.Clear();
m_file.Seek(last_valid_value_start, SEEK_SET);
delete[] value;
return m_num_entries;
}