Fix zstd ROM loading issues
* fix use-after-free of inContent * don't try to free the DStream twice
This commit is contained in:
parent
6112aa120a
commit
35cea5e1d7
|
@ -948,8 +948,8 @@ u32 DecompressROM(const u8* inContent, const u32 inSize, unique_ptr<u8[]>& outCo
|
||||||
|
|
||||||
if (realSize != ZSTD_CONTENTSIZE_UNKNOWN)
|
if (realSize != ZSTD_CONTENTSIZE_UNKNOWN)
|
||||||
{
|
{
|
||||||
outContent = make_unique<u8[]>(realSize);
|
auto newOutContent = make_unique<u8[]>(realSize);
|
||||||
u64 decompressed = ZSTD_decompress(outContent.get(), realSize, inContent, inSize);
|
u64 decompressed = ZSTD_decompress(newOutContent.get(), realSize, inContent, inSize);
|
||||||
|
|
||||||
if (ZSTD_isError(decompressed))
|
if (ZSTD_isError(decompressed))
|
||||||
{
|
{
|
||||||
|
@ -957,6 +957,7 @@ u32 DecompressROM(const u8* inContent, const u32 inSize, unique_ptr<u8[]>& outCo
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outContent = std::move(newOutContent);
|
||||||
return realSize;
|
return realSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1011,7 +1012,6 @@ u32 DecompressROM(const u8* inContent, const u32 inSize, unique_ptr<u8[]>& outCo
|
||||||
}
|
}
|
||||||
} while (inBuf.pos < inBuf.size);
|
} while (inBuf.pos < inBuf.size);
|
||||||
|
|
||||||
ZSTD_freeDStream(dStream);
|
|
||||||
outContent = make_unique<u8[]>(outBuf.pos);
|
outContent = make_unique<u8[]>(outBuf.pos);
|
||||||
memcpy(outContent.get(), outBuf.dst, outBuf.pos);
|
memcpy(outContent.get(), outBuf.dst, outBuf.pos);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue