Skip to content

ConstructorError handler accesses node.id causing AttributeError #907

Description

@coco1629

construct_yaml_float attempts to raise a ConstructorError when the input is not a ScalarNode. However, the error-handling code unconditionally accesses node.id when constructing the error message. When the passed object is not a Node type (e.g., a regular Python object, null, etc.), this causes an AttributeError.

obj = yaml.loader.SafeLoader("!!str")
ret = obj.construct_yaml_float(Null)

trace:

Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/fuzzwrap/fuzzwrap.py", line 748, in RunScript
    lib.RunFuzzer (Input)
  File "/root/check/failed/1#yaml#constructor#SafeConstructor#construct_yaml_float.py", line 34, in RunFuzzer
    output = dc.demoFunc(x)
  File "/root/check/failed/1#yaml#constructor#SafeConstructor#construct_yaml_float.py", line 27, in demoFunc
    ret = obj.construct_yaml_float(Null)
  File "/root/anaconda3/lib/python3.9/site-packages/yaml/constructor.py", line 271, in construct_yaml_float
    value = self.construct_scalar(node)
  File "/root/anaconda3/lib/python3.9/site-packages/yaml/constructor.py", line 178, in construct_scalar
    return super().construct_scalar(node)
  File "/root/anaconda3/lib/python3.9/site-packages/yaml/constructor.py", line 120, in construct_scalar
    "expected a scalar node, but found %s" % node.id,
AttributeError: type object 'xxlimited.Null' has no attribute 'id'

root cause:

def construct_scalar(self, node):
    if not isinstance(node, ScalarNode):
        raise ConstructorError(None, None,
                "expected a scalar node, but found %s" % node.id,  # ← here
                node.start_mark)
    return node.value

expected behavior:
Always raise ConstructorError, not crash with AttributeError due to error-handling failure

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions