lib/nbt: fix a bug in NBT::helper::readString() which caused it to asuume that dataSize is the size of the string

Soda
BodgeMaster 2022-08-15 09:51:46 +02:00
parent 9190cad80d
commit 884a5239c6
1 changed files with 7 additions and 2 deletions

View File

@ -146,11 +146,16 @@ namespace NBT {
}
ErrorOr<tiny_utf8::string> readString(uint8_t data[], uint64_t dataSize, uint64_t currentPosition) {
if(dataSize > 0xFFFF){
if(currentPosition > dataSize){
return ErrorOr<tiny_utf8::string>(true, ErrorCodes::OVERRUN);
}
ErrorOr<tiny_utf8::string> output = JavaCompat::importJavaString(data+currentPosition, (uint16_t) dataSize);
ErrorOr<int16_t> stringSize = readInt16(data, dataSize, currentPosition);
if (stringSize.isError) {
return ErrorOr<tiny_utf8::string>(true, stringSize.errorCode);
}
ErrorOr<tiny_utf8::string> output = JavaCompat::importJavaString(data+currentPosition, stringSize.value);
if(output.isError){
return ErrorOr<tiny_utf8::string>(true, output.errorCode);
}