Skip to content

AttributeError: 'Slice' object has no attribute 'qname' on fuzzed code #2721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
correctmost opened this issue Apr 10, 2025 · 1 comment
Open
Labels
Crash 💥 Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@correctmost
Copy link
Contributor

Steps to reproduce

The following code triggers an AttributeError in astroid:

s = slice(-2)
@s()
@six.add_metaclass()
class a: ...

This bug was discovered by OSS-Fuzz:
https://issues.oss-fuzz.com/issues/409585564 (report not public yet)

Current behavior

Traceback (most recent call last):
  File "pylint/lint/pylinter.py", line 994, in get_ast
    return MANAGER.ast_from_file(filepath, modname, source=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/manager.py", line 165, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/builder.py", line 145, in file_build
    return self._post_build(module, builder, encoding)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/builder.py", line 173, in _post_build
    module = self._manager.visit_transforms(module)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/manager.py", line 129, in visit_transforms
    return self._transform.visit(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/transforms.py", line 162, in visit
    return self._visit(node)
           ^^^^^^^^^^^^^^^^^
  File "astroid/transforms.py", line 84, in _visit
    visited = self._visit_generic(value)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/transforms.py", line 112, in _visit_generic
    return [self._visit_generic(child) for child in node]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/transforms.py", line 112, in <listcomp>
    return [self._visit_generic(child) for child in node]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/transforms.py", line 119, in _visit_generic
    return self._visit(node)
           ^^^^^^^^^^^^^^^^^
  File "astroid/transforms.py", line 87, in _visit
    return self._transform(node)
           ^^^^^^^^^^^^^^^^^^^^^
  File "astroid/transforms.py", line 67, in _transform
    ret = transform_func(node)
          ^^^^^^^^^^^^^^^^^^^^
  File "astroid/brain/brain_six.py", line 185, in transform_six_add_metaclass
    if func.qname() == SIX_ADD_METACLASS and decorator.args:
       ^^^^^^^^^^
AttributeError: 'Slice' object has no attribute 'qname'

Expected behavior

No crash

Version

ce81c29

@cdce8p
Copy link
Member

cdce8p commented Apr 10, 2025

Note that slice itself is not a callable, so the code above would fail in production as well.

>>> slice(-2)()
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    slice(-2)()
    ~~~~~~~~~^^
TypeError: 'slice' object is not callable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

3 participants