Skip to content

Commit d4b8bca

Browse files
committed
[GR-23238] [GR-24428] Fixed handling of overflow in PythonObjectLibrary.asSize()
PullRequest: graalpython/1073
2 parents da33164 + a0ccbee commit d4b8bca

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_list.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2019, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2020, Oracle and/or its affiliates.
22
# Copyright (C) 1996-2017 Python Software Foundation
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -91,6 +91,10 @@ def imul(a, b): a *= b
9191
self.assertRaises((MemoryError, OverflowError), mul, lst, n)
9292
self.assertRaises((MemoryError, OverflowError), imul, lst, n)
9393

94+
def test_large_index(self):
95+
lst = [0]
96+
self.assertRaises(IndexError, lambda: lst[2**100])
97+
9498
def test_repr_large(self):
9599

96100
# Check the repr of large list objects

graalpython/com.oracle.graal.python.test/src/tests/test_string.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def test_find():
5454
assert s.find('cau', MyIndexable(5), None) == 5
5555
assert s.find('cau', MyIndexable(5), MyIndexable(8)) == 5
5656
assert s.find('cau', None, MyIndexable(8)) == 5
57+
assert s.find('cau', 2**100) == -1
5758

5859

5960
def test_rfind():

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_int.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
*graalpython.lib-python.3.test.test_int.IntTestCases.test_basic
22
*graalpython.lib-python.3.test.test_int.IntTestCases.test_error_message
33
*graalpython.lib-python.3.test.test_int.IntTestCases.test_int_base_bad_types
4+
*graalpython.lib-python.3.test.test_int.IntTestCases.test_int_base_indexable
5+
*graalpython.lib-python.3.test.test_int.IntTestCases.test_int_base_limits
46
*graalpython.lib-python.3.test.test_int.IntTestCases.test_int_subclass_with_index
57
*graalpython.lib-python.3.test.test_int.IntTestCases.test_int_subclass_with_int
68
*graalpython.lib-python.3.test.test_int.IntTestCases.test_intconversion

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ Object parsePIntError(VirtualFrame frame, Object cls, String number, int base) {
14421442
@Specialization(guards = "!isNoValue(base)", limit = "getCallSiteInlineCacheMaxDepth()")
14431443
Object createIntError(VirtualFrame frame, Object cls, String number, Object base,
14441444
@CachedLibrary("base") PythonObjectLibrary lib) {
1445-
int intBase = lib.asSizeWithState(base, PArguments.getThreadState(frame));
1445+
int intBase = lib.asSizeWithState(base, null, PArguments.getThreadState(frame));
14461446
checkBase(intBase);
14471447
return stringToInt(frame, cls, number, intBase, number);
14481448
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongLossyNode.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public static CastToJavaLongLossyNode getUncached() {
6161

6262
@Specialization
6363
protected long toLong(PInt x) {
64-
return x.longValue();
64+
try {
65+
return x.longValueExact();
66+
} catch (ArithmeticException e) {
67+
if (x.isNegative()) {
68+
return Long.MIN_VALUE;
69+
} else {
70+
return Long.MAX_VALUE;
71+
}
72+
}
6573
}
6674
}

0 commit comments

Comments
 (0)