-
Bug
-
Resolution: Cannot Reproduce
-
None
-
1.20.50.20 Preview, 1.20.32 Hotfix
-
None
-
Unconfirmed
-
Multiple
Both classes ByteArrayTag and IntArrayTag use TagMemoryChunk to store data. The virtual function equals in both classes uses memcmp to compare whether the two data are equal.
The problem is that the strange naming of members in TagMemoryChunk makes it easy to make mistakes when using it. mElement is the number of elements, mSize is the capacity of the buffer, usually we use mSize, mCapacity instead of the former.
Element * sizeof(byte or int) (depending on the type of storage) is always less than or equal to mSize. when comparing two memoryChunks, you should compare the element * sizeof number of data, not the mSize number of data.
In BinaryNBT and NetworkNBT parsing, the mSize of the requested memorychunk is usually larger than the actual size, and those parts are uninitialized, which leads to the possibility that two identical nbt's may output false when calling equals.
Steps to Reproduce:
1. Create an NBT with a ByteArrayTag or IntArrayTag,
2. convert it to a BinaryNBT, then convert it back to an NBT, and
3. compare it to the previous NBT.
Observed Results:
High probability of outputting false (because the tail is not initialized).
Expected Results:
always true.
Solution: Use memcmp in the equals function of these two classes to compare the length of mElement * sizeof, not mSize.