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

OverflowError with SafeLoader found via fuzzing #843

Open
gvozdila opened this issue Feb 10, 2025 · 0 comments
Open

OverflowError with SafeLoader found via fuzzing #843

gvozdila opened this issue Feb 10, 2025 · 0 comments

Comments

@gvozdila
Copy link

gvozdila commented Feb 10, 2025

Hi! I'v found crash with OverflowError.

Way to reproduce

#!/usr/bin/python3

import yaml
import sys

with open(sys.argv[1], 'r', encoding="utf-8",errors='ignore') as inp_file:
    test_string = inp_file.read()
    yaml.safe_load(test_string)

Error message:

$ python3 test.py ./crash-test.txt
Traceback (most recent call last):
File "/root/test.py", line 8, in
yaml.safe_load(test_string)
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/init.py", line 125, in safe_load
return load(stream, SafeLoader)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/init.py", line 81, in load
return loader.get_single_data()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/constructor.py", line 49, in get_single_data
node = self.get_single_node()
^^^^^^^^^^^^^^^^^^^^^^
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/composer.py", line 35, in get_single_node
if not self.check_event(StreamEndEvent):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/parser.py", line 98, in check_event
self.current_event = self.state()
^^^^^^^^^^^^
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/parser.py", line 142, in parse_implicit_document_start
if not self.check_token(DirectiveToken, DocumentStartToken,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/scanner.py", line 116, in check_token
self.fetch_more_tokens()
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/scanner.py", line 251, in fetch_more_tokens
return self.fetch_double()
^^^^^^^^^^^^^^^^^^^
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/scanner.py", line 655, in fetch_double
self.fetch_flow_scalar(style='"')
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/scanner.py", line 666, in fetch_flow_scalar
self.tokens.append(self.scan_flow_scalar(style))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/scanner.py", line 1149, in scan_flow_scalar
chunks.extend(self.scan_flow_scalar_non_spaces(double, start_mark))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/ttt/lib/python3.11/site-packages/PyYAML-7.0.0.dev0-py3.11-linux-x86_64.egg/yaml/scanner.py", line 1217, in scan_flow_scalar_non_spaces
chunks.append(chr(code))
^^^^^^^^^
OverflowError: Python int too large to convert to C int

On some configs error "OverflowError: signed integer is greater than maximum"

Crash present at least from v6.0, appears with and without libyaml.

There is a patch in cpython fixing OverflowError to ValueError.
python/cpython@e2c4038

crash-test.txt

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