File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ What's New in astroid 4.0.0?
77============================
88Release date: TBA
99
10+ * Fix crashes with large positive and negative list multipliers.
11+
12+ Closes #2521
13+ Closes #2523
1014
1115
1216What's New in astroid 3.3.5?
Original file line number Diff line number Diff line change @@ -142,7 +142,10 @@ def _multiply_seq_by_int(
142142 context : InferenceContext ,
143143) -> _TupleListNodeT :
144144 node = self .__class__ (parent = opnode )
145- if value > 1e8 :
145+ if value <= 0 :
146+ node .elts = []
147+ return node
148+ if len (self .elts ) * value > 1e8 :
146149 node .elts = [util .Uninferable ]
147150 return node
148151 filtered_elts = (
Original file line number Diff line number Diff line change @@ -286,6 +286,23 @@ def test_uninferable_list_multiplication() -> None:
286286 element = parsed .inferred ()[0 ].elts [0 ]
287287 assert element .value is Uninferable
288288
289+ @staticmethod
290+ def test_uninferable_list_multiplication_with_multiple_operands () -> None :
291+ """Attempting to calculate the result is prohibitively expensive."""
292+ parsed = extract_node ("[0] * 825 * 16547118" )
293+ element = parsed .inferred ()[0 ].elts [0 ]
294+ assert element .value is Uninferable
295+
296+ @staticmethod
297+ def test_list_multiplication_with_zero_multiplier () -> None :
298+ parsed = extract_node ("[0] * 0" )
299+ assert parsed .inferred ()[0 ].elts == []
300+
301+ @staticmethod
302+ def test_list_multiplication_with_negative_multiplier () -> None :
303+ parsed = extract_node ("[0] * -9223372036854775809" )
304+ assert parsed .inferred ()[0 ].elts == []
305+
289306
290307def test_named_expr_inference () -> None :
291308 code = """
You can’t perform that action at this time.
0 commit comments