summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2022-11-08 20:00:19 (GMT)
committerGitHub <noreply@github.com>2022-11-08 20:00:19 (GMT)
commit0b4ffb08ccdc21fc07ce90d3f78b58a25e1af653 (patch)
treea8a7341c62dfd4a6c800f4ea411e762aa5604882 /Lib/enum.py
parent52f91c642b72003c57fc1fb855beab6dfab155b7 (diff)
downloadcpython-0b4ffb08ccdc21fc07ce90d3f78b58a25e1af653.zip
cpython-0b4ffb08ccdc21fc07ce90d3f78b58a25e1af653.tar.gz
cpython-0b4ffb08ccdc21fc07ce90d3f78b58a25e1af653.tar.bz2
gh-99248: [Enum] fix negative number infinite loop (GH-99256)
[Enum] fix negative number infinite loop - _iter_bits_lsb() now raises a ValueError if a negative number is passed in - verify() now skips checking negative numbers for named flags
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index c1ccf53..f6c34ea 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -114,9 +114,12 @@ def _make_class_unpicklable(obj):
setattr(obj, '__module__', '<unknown>')
def _iter_bits_lsb(num):
- # num must be an integer
+ # num must be a positive integer
+ original = num
if isinstance(num, Enum):
num = num.value
+ if num < 0:
+ raise ValueError('%r is not a positive integer' % original)
while num:
b = num & (~num + 1)
yield b
@@ -1839,6 +1842,9 @@ class verify:
if name in member_names:
# not an alias
continue
+ if alias.value < 0:
+ # negative numbers are not checked
+ continue
values = list(_iter_bits_lsb(alias.value))
missed = [v for v in values if v not in member_values]
if missed: