- use FileRdr in the PNG code, in particular to sanitize the savepic handling.
This commit is contained in:
parent
5fa63c396d
commit
c4387459bb
6 changed files with 84 additions and 95 deletions
|
|
@ -236,8 +236,8 @@ void FSavegameManager::ReadSaveStrings()
|
|||
}
|
||||
else // check for old formats.
|
||||
{
|
||||
FileReader file;
|
||||
if (file.Open(filepath))
|
||||
FileRdr file;
|
||||
if (file.OpenFile(filepath))
|
||||
{
|
||||
PNGHandle *png;
|
||||
char sig[16];
|
||||
|
|
@ -255,7 +255,7 @@ void FSavegameManager::ReadSaveStrings()
|
|||
|
||||
title[OLDSAVESTRINGSIZE] = 0;
|
||||
|
||||
if (nullptr != (png = M_VerifyPNG(&file, false)))
|
||||
if (nullptr != (png = M_VerifyPNG(file)))
|
||||
{
|
||||
char *ver = M_GetPNGText(png, "ZDoom Save Version");
|
||||
if (ver != nullptr)
|
||||
|
|
@ -272,7 +272,7 @@ void FSavegameManager::ReadSaveStrings()
|
|||
}
|
||||
else
|
||||
{
|
||||
file.Seek(0, SEEK_SET);
|
||||
file.Seek(0, FileRdr::SeekSet);
|
||||
if (file.Read(sig, 16) == 16)
|
||||
{
|
||||
|
||||
|
|
@ -496,29 +496,26 @@ unsigned FSavegameManager::ExtractSaveData(int index)
|
|||
FResourceLump *pic = resf->FindLump("savepic.png");
|
||||
if (pic != nullptr)
|
||||
{
|
||||
FileReader *reader = pic->NewReader();
|
||||
if (reader != nullptr)
|
||||
FileRdr picreader;
|
||||
|
||||
picreader.OpenMemoryArray([=](TArray<uint8_t> &array)
|
||||
{
|
||||
// copy to a memory buffer which gets accessed through a memory reader and PNGHandle.
|
||||
// We cannot use the actual lump as backing for the texture because that requires keeping the
|
||||
// savegame file open.
|
||||
SavePicData.Resize(pic->LumpSize);
|
||||
reader->Read(&SavePicData[0], pic->LumpSize);
|
||||
reader = new MemoryReader(&SavePicData[0], SavePicData.Size());
|
||||
PNGHandle *png = M_VerifyPNG(reader);
|
||||
if (png != nullptr)
|
||||
auto cache = pic->CacheLump();
|
||||
array.Resize(pic->LumpSize);
|
||||
memcpy(&array[0], cache, pic->LumpSize);
|
||||
pic->ReleaseCache();
|
||||
return true;
|
||||
});
|
||||
PNGHandle *png = M_VerifyPNG(picreader);
|
||||
if (png != nullptr)
|
||||
{
|
||||
SavePic = PNGTexture_CreateFromFile(png, node->Filename);
|
||||
delete png;
|
||||
if (SavePic->GetWidth() == 1 && SavePic->GetHeight() == 1)
|
||||
{
|
||||
SavePic = PNGTexture_CreateFromFile(png, node->Filename);
|
||||
currentSavePic = reader; // must be kept so that the texture can read from it.
|
||||
delete png;
|
||||
if (SavePic->GetWidth() == 1 && SavePic->GetHeight() == 1)
|
||||
{
|
||||
delete SavePic;
|
||||
SavePic = nullptr;
|
||||
delete currentSavePic;
|
||||
currentSavePic = nullptr;
|
||||
SavePicData.Clear();
|
||||
}
|
||||
delete SavePic;
|
||||
SavePic = nullptr;
|
||||
SavePicData.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -551,14 +548,9 @@ void FSavegameManager::UnloadSaveData()
|
|||
{
|
||||
V_FreeBrokenLines(SaveComment);
|
||||
}
|
||||
if (currentSavePic != nullptr)
|
||||
{
|
||||
delete currentSavePic;
|
||||
}
|
||||
|
||||
SavePic = nullptr;
|
||||
SaveComment = nullptr;
|
||||
currentSavePic = nullptr;
|
||||
SavePicData.Clear();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue