Skip to content

Commit

Permalink
prevent infinite loop on info
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Dec 24, 2024
1 parent cf2dbfe commit 412664d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions asdf/_node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import namedtuple

from .schema import load_schema
from .treeutil import get_children
from .treeutil import get_children, is_container


def _filter_tree(info, filters):
Expand Down Expand Up @@ -273,7 +273,7 @@ def from_root_node(
next_nodes = []

for parent, identifier, node in current_nodes:
if (isinstance(node, (dict, tuple)) or _traversable(node, extension_manager)) and id(node) in seen:
if (is_container(node) or _traversable(node, extension_manager)) and id(node) in seen:
info = NodeSchemaInfo(
key,
parent,
Expand Down
13 changes: 13 additions & 0 deletions asdf/_tests/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,3 +732,16 @@ def __asdf_traverse__(self):

captured = capsys.readouterr()
assert "sentinel" in captured.out


def test_info_no_infinite_loop(capsys):
"""
Providing a recursive list used to cause an
infinite loop. Test this is not the case.
"""
af = asdf.AsdfFile()
af["l"] = []
af["l"].append(af["l"])
af.info()
captured = capsys.readouterr()
assert "recursive" in captured.out

0 comments on commit 412664d

Please sign in to comment.