1
0
mirror of https://github.com/luanti-org/luanti.git synced 2026-01-12 20:25:26 +01:00

Serialize: Throw exception on incomplete reads (#16796)

Several mistakes were made past where the stream was expected to raise
the EOF flag when reaching the end of stream. That is incorrect. The
flag is only raised if the current read operation fails.

This commit unifies all istream compatibility code to use 'canRead'
for reliable EOF detection. An exception is now thrown when a
value cannot be read completely (e.g. missing bytes).
Version comments are added for easier backtracing.
This commit is contained in:
SmallJoker
2026-01-03 11:13:14 +01:00
committed by GitHub
parent 6079d762ce
commit 3d10d4e859
13 changed files with 207 additions and 179 deletions

View File

@@ -25,7 +25,8 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d
while (!data.empty()) { // breakable, run for one iteration
std::istringstream is(data, std::ios::binary);
// 'version' does not allow to incrementally extend the parameter list thus
// Servers < 5.0.0-dev (PROTOCOL_VERSION < 37) had improper compatibility code,
// only handling exactly 'version=0' and 'version=1'. See commit 67049eba. Thus,
// we need another variable to build on top of 'version=1'. Ugly hack but works™
u8 version2 = 0;
u8 version = readU8(is);
@@ -41,7 +42,7 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d
// yaw must be yaw to be backwards-compatible
rotation.Y = readF1000(is);
if (is.good()) // EOF for old formats
if (canRead(is))
version2 = readU8(is);
if (version2 < 1) // PROTOCOL_VERSION < 37