From aab91a25230e8cbd5e591e289ef32fa0f3b67a32 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Sun, 11 Sep 2022 09:14:32 +0200 Subject: [PATCH] lib/nbt: Fix NBT::validateRawNBTData() and NBT::validateRawListContents closing #52 and #53 --- src/lib/nbt.cpp | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index 2bd8840..ba80d7e 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -595,18 +595,20 @@ namespace NBT { } } - bool validateRawList(uint8_t data[], uint64_t dataSize, uint64_t initialPosition, uint64_t* processedDataSize) { - ErrorOr elementCount = helper::containedDataLength(data, dataSize, initialPosition); + bool validateRawListContents(uint8_t data[], uint64_t dataSize, uint64_t initialPosition, uint64_t* processedDataSize) { + // get contained data length by reading it manually because + // the function that does it normally can't deal with + // headerless tags + // + // add one byte to position to skip the type byte + ErrorOr elementCount = helper::readInt32(data, dataSize, initialPosition+1); if (elementCount.isError) { return false; } - // there is no way this is an error bc it gets checked while trying - // to get the element count - int16_t nameSize = helper::readInt16(data, dataSize, initialPosition+1).value; - // 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 = (uint64_t) nameSize + 8; + + uint8_t contentType = data[initialPosition]; + // contained type byte + 4 length bytes = 5 + *processedDataSize = 5; switch (contentType) { case TagType::END: // everything except content has been touched at this point @@ -656,7 +658,8 @@ namespace NBT { uint64_t* containedDataSize = new uint64_t; for (int32_t i=0; i