From 437238a0bdddf2ca500b7dea7cd7ed87e4c3130f Mon Sep 17 00:00:00 2001 From: howsohazard <143410553+howsohazard@users.noreply.github.com> Date: Wed, 31 Jan 2024 07:48:14 -0500 Subject: [PATCH] 19163: Fixes memory corruption issue (#68) --- src/Amalgam/evaluablenode/EvaluableNode.cpp | 9 ++++++++- src/Amalgam/evaluablenode/EvaluableNodeTreeFunctions.cpp | 2 -- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Amalgam/evaluablenode/EvaluableNode.cpp b/src/Amalgam/evaluablenode/EvaluableNode.cpp index 6036fa39..b4f1427e 100644 --- a/src/Amalgam/evaluablenode/EvaluableNode.cpp +++ b/src/Amalgam/evaluablenode/EvaluableNode.cpp @@ -423,9 +423,12 @@ void EvaluableNode::InitializeType(EvaluableNode *n, bool copy_labels, bool copy void EvaluableNode::CopyValueFrom(EvaluableNode *n) { + //don't do anything if copying from itself (note that some flat hash map structures don't copy well onto themselves) + if(n == this) + return; + if(n == nullptr) { - ClearOrderedChildNodes(); ClearMappedChildNodes(); //doesn't need an EvaluableNodeManager because not converting child nodes from one type to another @@ -466,6 +469,10 @@ void EvaluableNode::CopyValueFrom(EvaluableNode *n) void EvaluableNode::CopyMetadataFrom(EvaluableNode *n) { + //don't do anything if copying from itself + if(n == this) + return; + //copy labels (different ways based on type) if(HasCompactSingleLabelStorage() && n->HasCompactSingleLabelStorage()) { diff --git a/src/Amalgam/evaluablenode/EvaluableNodeTreeFunctions.cpp b/src/Amalgam/evaluablenode/EvaluableNodeTreeFunctions.cpp index f6682096..e7a7d279 100644 --- a/src/Amalgam/evaluablenode/EvaluableNodeTreeFunctions.cpp +++ b/src/Amalgam/evaluablenode/EvaluableNodeTreeFunctions.cpp @@ -461,12 +461,10 @@ EvaluableNodeReference AccumulateEvaluableNodeIntoEvaluableNode(EvaluableNodeRef if(EvaluableNode::IsAssociativeArray(variable_value_node)) { - new_list->SetMappedChildNodes(value_destination_node->GetMappedChildNodes(), true); new_list->AppendMappedChildNodes(variable_value_node->GetMappedChildNodes()); } else if(variable_value_node != nullptr) //treat ordered pairs as new entries as long as not nullptr { - new_list->SetMappedChildNodes(value_destination_node->GetMappedChildNodes(), true); //iterate as long as pairs exist auto &vvn_ocn = variable_value_node->GetOrderedChildNodes(); for(size_t i = 0; i + 1 < vvn_ocn.size(); i += 2)