Skip to content
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

Uncaught exception in get_normalizer_issues #219

Open
DavidKorczynski opened this issue Mar 14, 2023 · 0 comments
Open

Uncaught exception in get_normalizer_issues #219

DavidKorczynski opened this issue Mar 14, 2023 · 0 comments

Comments

@DavidKorczynski
Copy link

Hello,

We have been trying to fuzz parso to help catch any uncaught exceptions that may occur. We found that the following program generates an uncaught exception:

import sys
import atheris
import parso

def TestOneInput(data):
  fdp = atheris.FuzzedDataProvider(data)
  try:
    grammar = parso.load_grammar()
    module = parso.parse(fdp.ConsumeUnicodeNoSurrogates(sys.maxsize))
    if module != None:
        grammar._get_normalizer_issues(module)
  except RecursionError:
    # Not interesting
    pass

data = (b"\xff\x5c\x0a\x23")
TestOneInput(data)

The Atheris module used is https://pypi.org/project/atheris/ FuzzedDataProvider is used to convert the raw bytes in data into appropriate types.

If we write out the value generated by fdp.ConsumeUnicodeNoSurrogates in the above example, we can create the following program to trigger the issue:

import parso

grammar = parso.load_grammar()
module = parso.parse("\\\n#")
if module is not None:
  grammar._get_normalizer_issues(module

The traceback is:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/parso/normalizer.py", line 42, in visit
    children = node.children
AttributeError: 'EndMarker' object has no attribute 'children'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./reproducer.py", line 6, in <module>
    grammar._get_normalizer_issues(module)
  File "/usr/local/lib/python3.8/site-packages/parso/grammar.py", line 203, in _get_normalizer_issues
    normalizer.walk(node)
  File "/usr/local/lib/python3.8/site-packages/parso/normalizer.py", line 36, in walk
    value = self.visit(node)
  File "/usr/local/lib/python3.8/site-packages/parso/python/errors.py", line 408, in visit
    return super().visit(node)
  File "/usr/local/lib/python3.8/site-packages/parso/normalizer.py", line 47, in visit
    return ''.join(self.visit(child) for child in children)
  File "/usr/local/lib/python3.8/site-packages/parso/normalizer.py", line 47, in <genexpr>
    return ''.join(self.visit(child) for child in children)
  File "/usr/local/lib/python3.8/site-packages/parso/python/errors.py", line 408, in visit
    return super().visit(node)
  File "/usr/local/lib/python3.8/site-packages/parso/normalizer.py", line 44, in visit
    return self.visit_leaf(node)
  File "/usr/local/lib/python3.8/site-packages/parso/python/pep8.py", line 350, in visit_leaf
    self._visit_part(part, part.create_spacing_part(), leaf)
  File "/usr/local/lib/python3.8/site-packages/parso/python/pep8.py", line 441, in _visit_part
    if len(indentation) > len(n.indentation):
AttributeError: 'NoneType' object has no attribute 'indentation'

This was found by way of OSS-Fuzz and the set up here: https://github.com/google/oss-fuzz/tree/master/projects/parso If you find this issue helpful then it would be great to have maintainer emails in the project.yaml to receive notifications of bug reports, which contain all of the details similar to what I posted above.

@DavidKorczynski DavidKorczynski changed the title Uncaught exception in `get_normalizer_issues Uncaught exception in get_normalizer_issues Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant