Compare commits
No commits in common. "aab91a25230e8cbd5e591e289ef32fa0f3b67a32" and "48f8a7dcf28ed34e88c7b91eb509b704586bb996" have entirely different histories.
aab91a2523
...
48f8a7dcf2
|
@ -38,7 +38,7 @@ namespace JavaCompat {
|
|||
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(data[i] == 0x80 && data[i-1] == 0xc0){
|
||||
stdString[stdString.length() - 1] = '\0';
|
||||
|
|
|
@ -595,20 +595,18 @@ namespace NBT {
|
|||
}
|
||||
}
|
||||
|
||||
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<int32_t> elementCount = helper::readInt32(data, dataSize, initialPosition+1);
|
||||
bool validateRawList(uint8_t data[], uint64_t dataSize, uint64_t initialPosition, uint64_t* processedDataSize) {
|
||||
ErrorOr<int32_t> elementCount = helper::containedDataLength(data, dataSize, initialPosition);
|
||||
if (elementCount.isError) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t contentType = data[initialPosition];
|
||||
// contained type byte + 4 length bytes = 5
|
||||
*processedDataSize = 5;
|
||||
// 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;
|
||||
switch (contentType) {
|
||||
case TagType::END:
|
||||
// everything except content has been touched at this point
|
||||
|
@ -658,8 +656,7 @@ namespace NBT {
|
|||
uint64_t* containedDataSize = new uint64_t;
|
||||
for (int32_t i=0; i<elementCount.value; i++) {
|
||||
*containedDataSize = 0;
|
||||
|
||||
if (validateRawListContents(data, dataSize, initialPosition+*processedDataSize, containedDataSize)) {
|
||||
if (validateRawList(data, dataSize, initialPosition+*processedDataSize, containedDataSize)) {
|
||||
*processedDataSize += *containedDataSize;
|
||||
} else {
|
||||
delete containedDataSize;
|
||||
|
@ -673,7 +670,7 @@ namespace NBT {
|
|||
uint64_t* containedDataSize = new uint64_t;
|
||||
for (int32_t i=0; i<elementCount.value; i++) {
|
||||
*containedDataSize = 0;
|
||||
if (validateRawNBTData(data, dataSize, initialPosition+*processedDataSize, containedDataSize)) {
|
||||
if (validateRawNBTData(data, dataSize, initialPosition, containedDataSize)) {
|
||||
*processedDataSize += *containedDataSize;
|
||||
} else {
|
||||
delete containedDataSize;
|
||||
|
@ -746,24 +743,22 @@ namespace NBT {
|
|||
return false;
|
||||
}
|
||||
|
||||
// used seek to the start of the list's/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;
|
||||
|
||||
uint64_t* processedTagSize = new uint64_t;
|
||||
*processedTagSize = 0;
|
||||
|
||||
if (data[currentPosition]==TagType::LIST) {
|
||||
// type byte + two name size bytes = 3
|
||||
if (!validateRawListContents(data, dataSize, currentPosition + (uint64_t) nameSize + 3, processedTagSize)) {
|
||||
if (!validateRawList(data, dataSize, currentPosition, processedTagSize)) {
|
||||
delete processedTagSize;
|
||||
return false;
|
||||
}
|
||||
*processedTagSize += (uint64_t) nameSize + 3;
|
||||
}
|
||||
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
|
||||
if (!validateRawNBTData(data, dataSize, currentPosition + (uint64_t) nameSize + 3, processedTagSize)) {
|
||||
delete processedTagSize;
|
||||
|
|
Loading…
Reference in New Issue