Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1109,15 +1109,13 @@ public void deserialize(final InputStream inputStream) throws IOException {
name = tableNode.getName();
stack.push(new Pair<>(tableNode, false));
} else {
// Currently internal mNode will not be the leaf node and thus will not be deserialized here
// This is just in case
internalMNode = deserializeInternalMNode(inputStream);
ReadWriteIOUtils.readInt(inputStream);
name = internalMNode.getName();
stack.push(new Pair<>(internalMNode, false));
}

while (!PATH_ROOT.equals(name)) {
while (!PATH_ROOT.equals(name) || type != INTERNAL_MNODE_TYPE) {
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop termination condition has a logical flaw. It will incorrectly stop when encountering any internal node named "root", not just the tree root. For example, if there's a path like "root.a.root.b.sg" where root is an escaped internal node name, the deserialization would terminate prematurely at that internal node.

The condition should ensure we've reached the actual tree root, which is the last node serialized. One approach is to check if the stack has accumulated all the tree content, or use a different marker to identify the tree root specifically.

Suggested change
while (!PATH_ROOT.equals(name) || type != INTERNAL_MNODE_TYPE) {
while (stack.size() != 1 || !PATH_ROOT.equals(name) || type != INTERNAL_MNODE_TYPE) {

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stack size cannot reflect whether the "root" is an internal node.... "root.a.root.b.sg" will cause the stack to be (sg, b, root, a, root), and the stack size always == 1. Besides, a pattern like this will not pass the partial path AST check.

type = ReadWriteIOUtils.readByte(inputStream);
switch (type) {
case INTERNAL_MNODE_TYPE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void testGetNodeListInLevel() throws MetadataException {
public void testSerialization() throws Exception {
final PartialPath[] pathList =
new PartialPath[] {
new PartialPath("root.sg"),
new PartialPath("root.`root`"),
new PartialPath("root.a.sg"),
new PartialPath("root.a.b.sg"),
new PartialPath("root.a.a.b.sg")
Expand Down