lib/nbt: Prevent addition of additional end tags to compounds
parent
71834e1018
commit
7be73f86d4
|
@ -988,9 +988,16 @@ namespace NBT {
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOrVoid Compound::setElementPointerAt(uint64_t position, Generic* pointer) {
|
ErrorOrVoid Compound::setElementPointerAt(uint64_t position, Generic* pointer) {
|
||||||
// built-in end tag
|
if (position == this->tags.size() || pointer->getTagType() == TagType::END) {
|
||||||
if (position == this->tags.size()) {
|
if (position == this->tags.size() && pointer->getTagType() == TagType::END) {
|
||||||
return ErrorOrVoid(true, ErrorCodes::NOT_ALLOWED);
|
delete pointer;
|
||||||
|
// do nothing, already have one of those
|
||||||
|
} else {
|
||||||
|
delete pointer;
|
||||||
|
// End tags may only go at the end and
|
||||||
|
// the end may only hold an end tag.
|
||||||
|
return ErrorOrVoid(true, ErrorCodes::NOT_ALLOWED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (position > this->tags.size()) {
|
if (position > this->tags.size()) {
|
||||||
return ErrorOrVoid(true, ErrorCodes::OUT_OF_RANGE);
|
return ErrorOrVoid(true, ErrorCodes::OUT_OF_RANGE);
|
||||||
|
@ -1002,8 +1009,12 @@ namespace NBT {
|
||||||
return ErrorOrVoid();
|
return ErrorOrVoid();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compound::appendPointer(Generic* pointer) {
|
ErrorOrVoid Compound::appendPointer(Generic* pointer) {
|
||||||
|
if (pointer->getTagType() == TagType::END) {
|
||||||
|
return ErrorOrVoid(true, ErrorCodes::NOT_ALLOWED);
|
||||||
|
}
|
||||||
this->tags.push_back(pointer);
|
this->tags.push_back(pointer);
|
||||||
|
return ErrorOrVoid();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOrVoid Compound::deleteElement(uint64_t position) {
|
ErrorOrVoid Compound::deleteElement(uint64_t position) {
|
||||||
|
|
|
@ -257,7 +257,7 @@ namespace NBT {
|
||||||
|
|
||||||
ErrorOr<Generic*> getElementPointer(uint64_t position);
|
ErrorOr<Generic*> getElementPointer(uint64_t position);
|
||||||
ErrorOrVoid setElementPointerAt(uint64_t position, Generic* pointer);
|
ErrorOrVoid setElementPointerAt(uint64_t position, Generic* pointer);
|
||||||
void appendPointer(Generic* pointer);
|
ErrorOrVoid appendPointer(Generic* pointer);
|
||||||
ErrorOrVoid deleteElement(uint64_t position);
|
ErrorOrVoid deleteElement(uint64_t position);
|
||||||
uint64_t length();
|
uint64_t length();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue