Skip to content

Commit

Permalink
Fix zstd ROM loading issues
Browse files Browse the repository at this point in the history
* fix use-after-free of inContent
* don't try to free the DStream twice
  • Loading branch information
nadiaholmquist committed May 4, 2024
1 parent 6112aa1 commit 35cea5e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/frontend/qt_sdl/ROMManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,15 +948,16 @@ u32 DecompressROM(const u8* inContent, const u32 inSize, unique_ptr<u8[]>& outCo

if (realSize != ZSTD_CONTENTSIZE_UNKNOWN)
{
outContent = make_unique<u8[]>(realSize);
u64 decompressed = ZSTD_decompress(outContent.get(), realSize, inContent, inSize);
auto newOutContent = make_unique<u8[]>(realSize);
u64 decompressed = ZSTD_decompress(newOutContent.get(), realSize, inContent, inSize);

if (ZSTD_isError(decompressed))
{
outContent = nullptr;
return 0;
}

outContent = std::move(newOutContent);
return realSize;
}
else
Expand Down Expand Up @@ -1011,7 +1012,6 @@ u32 DecompressROM(const u8* inContent, const u32 inSize, unique_ptr<u8[]>& outCo
}
} while (inBuf.pos < inBuf.size);

ZSTD_freeDStream(dStream);
outContent = make_unique<u8[]>(outBuf.pos);
memcpy(outContent.get(), outBuf.dst, outBuf.pos);

Expand Down

0 comments on commit 35cea5e

Please sign in to comment.