From 25bec4c58794faf1dea1a0dc14796f566f7267f8 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Mon, 15 Aug 2022 10:51:50 +0200 Subject: [PATCH] lib/nbt: Validator: Fix bytes not being added up correctly in multiple places --- src/lib/nbt.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index 1c91f35..0dd3e4e 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -585,7 +585,7 @@ namespace NBT { // type byte + two name size bytes = 3 uint8_t contentType = data[initialPosition + nameSize + 3]; // type byte + two name size bytes + contained type byte + 4 length bytes = 8 - *processedDataSize = 8; + *processedDataSize = (uint64_t) nameSize + 8; switch (contentType) { case TagType::END: // everything except content has been touched at this point @@ -738,11 +738,12 @@ namespace NBT { // checked while trying to parse the string above int16_t nameSize = helper::readInt16(data, dataSize, currentPosition+1).value; - if (!validateRawNBTData(data, dataSize, currentPosition + (uint64_t) nameSize + 1, processedTagSize)) { + // type byte + two name size bytes = 3 + if (!validateRawNBTData(data, dataSize, currentPosition + (uint64_t) nameSize + 3, processedTagSize)) { delete processedTagSize; return false; } - *processedTagSize += (uint64_t) nameSize + 1; + *processedTagSize += (uint64_t) nameSize + 3; } currentPosition += *processedTagSize; @@ -758,6 +759,7 @@ namespace NBT { // recursion abort condition if (data[currentPosition]==TagType::END) { + currentPosition++; return true; }