1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Increase limit of serialized long strings

This commit is contained in:
kwolekr 2015-07-14 03:22:16 -04:00
parent 5006ce8260
commit 515e7028ac
2 changed files with 10 additions and 4 deletions

View file

@ -126,6 +126,10 @@ std::wstring deSerializeWideString(std::istream &is)
std::string serializeLongString(const std::string &plain)
{
char buf[4];
if (plain.size() > LONG_STRING_MAX)
throw SerializationError("String too long for serializeLongString");
writeU32((u8*)&buf[0], plain.size());
std::string s;
s.append(buf, 4);
@ -147,8 +151,10 @@ std::string deSerializeLongString(std::istream &is)
return s;
// We don't really want a remote attacker to force us to allocate 4GB...
if (s_size > LONG_STRING_MAX)
throw SerializationError("deSerializeLongString: string too long");
if (s_size > LONG_STRING_MAX) {
throw SerializationError("deSerializeLongString: "
"string too long: " + itos(s_size) + " bytes");
}
Buffer<char> buf2(s_size);
is.read(&buf2[0], s_size);