FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-141778: Missing validation for allowed constant values in `ast.literal_eval()` by XChaitanyaX · Pull Request #141933 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 8 additions & 2 deletions Lib/ast.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"""
from _ast import *

type_None = type(None)
type_Ellipsis = type(...)

def parse(source, filename='<unknown>', mode='exec', *,
type_comments=False, feature_version=None, optimize=-1, module=None):
Expand Down Expand Up @@ -68,8 +70,12 @@ def _convert_literal(node):
"""
Used by `literal_eval` to convert an AST node into a value.
"""
if isinstance(node, Constant):
return node.value
if (
isinstance(node, Constant)
and type(value := node.value) in (int, float, complex, bytes, bool, str, bytes,
type_None, type_Ellipsis)
):
return value
if isinstance(node, Dict) and len(node.keys) == len(node.values):
return dict(zip(
map(_convert_literal, node.keys),
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing validation for allowed constant values in :func:`ast.literal_eval`.
Loading

Back | FazBrowse Home | New Git URL