Compare commits

..

No commits in common. "aab91a25230e8cbd5e591e289ef32fa0f3b67a32" and "48f8a7dcf28ed34e88c7b91eb509b704586bb996" have entirely different histories.

2 changed files with 19 additions and 24 deletions

View File

@ -38,7 +38,7 @@ namespace JavaCompat {
return ErrorOr<tiny_utf8::string>(true, ErrorCodes::MISMATCHEDSIZE); return ErrorOr<tiny_utf8::string>(true, ErrorCodes::MISMATCHEDSIZE);
} }
for(uint16_t i=2; i<size+2; i++){ for(uint8_t i=2; i<size+2; i++){
if(i != 0){ if(i != 0){
if(data[i] == 0x80 && data[i-1] == 0xc0){ if(data[i] == 0x80 && data[i-1] == 0xc0){
stdString[stdString.length() - 1] = '\0'; stdString[stdString.length() - 1] = '\0';

View File

@ -595,20 +595,18 @@ namespace NBT {
} }
} }
bool validateRawListContents(uint8_t data[], uint64_t dataSize, uint64_t initialPosition, uint64_t* processedDataSize) { bool validateRawList(uint8_t data[], uint64_t dataSize, uint64_t initialPosition, uint64_t* processedDataSize) {
// get contained data length by reading it manually because ErrorOr<int32_t> elementCount = helper::containedDataLength(data, dataSize, initialPosition);
// the function that does it normally can't deal with
// headerless tags
//
// add one byte to position to skip the type byte
ErrorOr<int32_t> elementCount = helper::readInt32(data, dataSize, initialPosition+1);
if (elementCount.isError) { if (elementCount.isError) {
return false; return false;
} }
// there is no way this is an error bc it gets checked while trying
uint8_t contentType = data[initialPosition]; // to get the element count
// contained type byte + 4 length bytes = 5 int16_t nameSize = helper::readInt16(data, dataSize, initialPosition+1).value;
*processedDataSize = 5; // 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;
switch (contentType) { switch (contentType) {
case TagType::END: case TagType::END:
// everything except content has been touched at this point // everything except content has been touched at this point
@ -658,8 +656,7 @@ namespace NBT {
uint64_t* containedDataSize = new uint64_t; uint64_t* containedDataSize = new uint64_t;
for (int32_t i=0; i<elementCount.value; i++) { for (int32_t i=0; i<elementCount.value; i++) {
*containedDataSize = 0; *containedDataSize = 0;
if (validateRawList(data, dataSize, initialPosition+*processedDataSize, containedDataSize)) {
if (validateRawListContents(data, dataSize, initialPosition+*processedDataSize, containedDataSize)) {
*processedDataSize += *containedDataSize; *processedDataSize += *containedDataSize;
} else { } else {
delete containedDataSize; delete containedDataSize;
@ -673,7 +670,7 @@ namespace NBT {
uint64_t* containedDataSize = new uint64_t; uint64_t* containedDataSize = new uint64_t;
for (int32_t i=0; i<elementCount.value; i++) { for (int32_t i=0; i<elementCount.value; i++) {
*containedDataSize = 0; *containedDataSize = 0;
if (validateRawNBTData(data, dataSize, initialPosition+*processedDataSize, containedDataSize)) { if (validateRawNBTData(data, dataSize, initialPosition, containedDataSize)) {
*processedDataSize += *containedDataSize; *processedDataSize += *containedDataSize;
} else { } else {
delete containedDataSize; delete containedDataSize;
@ -746,24 +743,22 @@ namespace NBT {
return false; return false;
} }
// used seek to the start of the list's/compounds contents
//
// there is no way this is an error bc it gets
// checked while trying to parse the string above
int16_t nameSize = helper::readInt16(data, dataSize, currentPosition+1).value;
uint64_t* processedTagSize = new uint64_t; uint64_t* processedTagSize = new uint64_t;
*processedTagSize = 0; *processedTagSize = 0;
if (data[currentPosition]==TagType::LIST) { if (data[currentPosition]==TagType::LIST) {
// type byte + two name size bytes = 3 if (!validateRawList(data, dataSize, currentPosition, processedTagSize)) {
if (!validateRawListContents(data, dataSize, currentPosition + (uint64_t) nameSize + 3, processedTagSize)) {
delete processedTagSize; delete processedTagSize;
return false; return false;
} }
*processedTagSize += (uint64_t) nameSize + 3;
} }
if (data[currentPosition]==TagType::COMPOUND) { if (data[currentPosition]==TagType::COMPOUND) {
// seek to the start of the compound's contents
//
// there is no way this is an error bc it gets
// checked while trying to parse the string above
int16_t nameSize = helper::readInt16(data, dataSize, currentPosition+1).value;
// type byte + two name size bytes = 3 // type byte + two name size bytes = 3
if (!validateRawNBTData(data, dataSize, currentPosition + (uint64_t) nameSize + 3, processedTagSize)) { if (!validateRawNBTData(data, dataSize, currentPosition + (uint64_t) nameSize + 3, processedTagSize)) {
delete processedTagSize; delete processedTagSize;