@@ -350,11 +350,21 @@ def _parse_maple_tree_node(
350350 maple_tree_entry ,
351351 parent ,
352352 expected_maple_tree_depth ,
353- seen = set () ,
353+ seen = None ,
354354 current_depth = 1 ,
355355 ):
356356 """Recursively parse Maple Tree Nodes and yield all non empty slots"""
357357
358+ # Create seen set if it does not exist, e.g. on the first call into this recursive function. This
359+ # must be None or an existing set of addresses for MTEs that have already been processed or that
360+ # should otherwise be ignored. If parsing from the root node for example this should be None on the
361+ # first call. If you needed to parse all nodes downwards from part of the tree this should still be
362+ # None. If however you wanted to parse from a node, but ignore some parts of the tree below it then
363+ # this could be populated with the addresses of the nodes you wish to ignore.
364+
365+ if seen == None :
366+ seen = set ()
367+
358368 # protect against unlikely loop
359369 if maple_tree_entry in seen :
360370 vollog .warning (
@@ -363,6 +373,7 @@ def _parse_maple_tree_node(
363373 return None
364374 else :
365375 seen .add (maple_tree_entry )
376+
366377 # check if we have exceeded the expected depth of this maple tree.
367378 # e.g. when current_depth is larger than expected_maple_tree_depth there may be an issue.
368379 # it is normal that expected_maple_tree_depth is equal to current_depth.
@@ -371,6 +382,7 @@ def _parse_maple_tree_node(
371382 f"The depth for the maple tree at { hex (self .vol .offset )} is { expected_maple_tree_depth } , however when parsing the nodes "
372383 f"a depth of { current_depth } was reached. This is unexpected and may lead to incorrect results."
373384 )
385+
374386 # parse the mte to extract the pointer value, node type, and leaf status
375387 pointer = maple_tree_entry & ~ (self .MAPLE_NODE_POINTER_MASK )
376388 node_type = (
0 commit comments