mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-10-23 20:18:10 +00:00
fix: increased iw4 and iw5 peeking may result in a failbit in the stream
This commit is contained in:
2 files changed
+9
No files matched your search
@@ -7,12 +7,18 @@ ZoneDataPeeking::ZoneDataPeeking(std::istream& stream)
|
||||
|
||||
void ZoneDataPeeking::PeekWithStream(const std::function<void(std::istream& stream)>& cb) const
|
||||
{
|
||||
const auto previousBits = m_stream.rdstate();
|
||||
// Clear any bits set previously
|
||||
m_stream.clear();
|
||||
|
||||
const auto previousPos = m_stream.tellg();
|
||||
m_stream.seekg(0, std::ios::beg);
|
||||
|
||||
cb(m_stream);
|
||||
|
||||
m_stream.clear();
|
||||
m_stream.seekg(previousPos);
|
||||
m_stream.setstate(previousBits);
|
||||
}
|
||||
|
||||
void ZoneDataPeeking::EnsureHasEnoughData(const size_t size)
|
||||
|
||||
@@ -36,6 +36,9 @@ std::expected<std::unique_ptr<Zone>, std::string> ZoneLoading::LoadZone(const st
|
||||
if (!zoneLoader)
|
||||
return std::unexpected(std::format("Could not create factory for zone '{}'.", zoneName));
|
||||
|
||||
// We may have to clear a fail bit if the peeking resulted in eof.
|
||||
// Otherwise, we cannot seek.
|
||||
file.clear();
|
||||
// Revert to beginning to make sure no peeking has advanced the read position.
|
||||
// (As different peeking logic may advance by different amounts of bytes).
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
Reference in new issue
Block a user