Skip to content

Add PyExc_OverflowError to the list of possible exceptions in fuzz_ast_literal_eval fuzzer - #145429

Merged
encukou merged 1 commit into
python:mainfrom
StanFromIreland:fix-fuzz_ast_literal_eval
Mar 3, 2026
Merged

encukou merged 1 commit into
python:mainfrom
StanFromIreland:fix-fuzz_ast_literal_eval

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Mar 2, 2026

Copy link
Copy Markdown
Member

This fixes the "bug" found in https://oss-fuzz.com/testcase-detail/5450638250278912.

>>> import ast
... data = open('/tmp/testcase', 'rb').read()
... ast.literal_eval(data[:data.index(0)].decode())
... 
<python-input-2>:2: ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/testcase'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
  File "<python-input-2>", line 3, in <module>
    ast.literal_eval(data[:data.index(0)].decode())
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stan/dev/cpython/Lib/ast.py", line 64, in literal_eval
    return _convert_literal(node_or_string)
  File "/home/stan/dev/cpython/Lib/ast.py", line 108, in _convert_literal
    return left + right
           ~~~~~^~~~~~~
OverflowError: int too large to convert to float
With fuzzer

Currently:

$ ./python -c "
import _xxtestfuzz
data = open('/tmp/testcase', 'rb').read()
_xxtestfuzz.run(data)
"
<string>:3: ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/testcase'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
  File "/home/stan/dev/cpython/Lib/ast.py", line 64, in literal_eval
    return _convert_literal(node_or_string)
  File "/home/stan/dev/cpython/Lib/ast.py", line 108, in _convert_literal
    return left + right
           ~~~~~^~~~~~~
OverflowError: int too large to convert to float
Aborted (core dumped)

With fix:

$ ./python -c "
import _xxtestfuzz
data = open('/tmp/testcase', 'rb').read()
_xxtestfuzz.run(data)
"
<string>:3: ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/testcase'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback

@ammaraskar ammaraskar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to ignore this, we don't particularly care about overflow here.

@encukou
encukou merged commit a929e80 into python:main Mar 3, 2026
57 checks passed
@StanFromIreland
StanFromIreland deleted the fix-fuzz_ast_literal_eval branch March 3, 2026 13:20
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@hugovk

hugovk commented Sep 24, 2026

Copy link
Copy Markdown
Member

Let's backport this?

Failing CIFuzz doesn't block merge but is often distracting, for example #158015 on 3.13.

@encukou encukou added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Sep 24, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @StanFromIreland for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app

Copy link
Copy Markdown

Thanks @StanFromIreland for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @StanFromIreland for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@encukou encukou removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 24, 2026
@miss-islington-app

This comment was marked as outdated.

@bedevere-app

bedevere-app Bot commented Sep 24, 2026

Copy link
Copy Markdown

GH-158083 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Sep 24, 2026
@bedevere-app

bedevere-app Bot commented Sep 24, 2026

Copy link
Copy Markdown

GH-158084 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 24, 2026
hugovk pushed a commit that referenced this pull request Sep 24, 2026
…n `fuzz_ast_literal_eval` fuzzer (GH-145429) (#158083)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
hugovk pushed a commit that referenced this pull request Sep 24, 2026
…n `fuzz_ast_literal_eval` fuzzer (GH-145429) (#158084)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@StanFromIreland

StanFromIreland commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

Personally, I'd rather remove them from the CI on those branches entirely, but this is fine in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip issue skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants