fix: increased iw4 and iw5 peeking may result in a failbit in the stream

This commit is contained in:
Jan Laupetin committed 2026-10-22 20:01:07 +02:00
1 parent 0df7f16158
commit 53c279ff4c
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)
+3
View File
@@ -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);