Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c317e7

Browse files
Issue #27286: Fixed compiling BUILD_MAP_UNPACK_WITH_CALL opcode. Calling
function with generalized unpacking (PEP 448) and conflicting keyword names could cause undefined behavior.
1 parent 4f8aaf6 commit 3c317e7

7 files changed

Lines changed: 121 additions & 107 deletions

File tree

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def _write_atomic(path, data, mode=0o666):
223223
# Python 3.5b1 3330 (PEP 448: Additional Unpacking Generalizations)
224224
# Python 3.5b2 3340 (fix dictionary display evaluation order #11205)
225225
# Python 3.5b2 3350 (add GET_YIELD_FROM_ITER opcode #24400)
226+
# Python 3.5.2 3351 (fix BUILD_MAP_UNPACK_WITH_CALL opcode #27286)
226227
#
227228
# MAGIC must change whenever the bytecode emitted by the compiler may no
228229
# longer be understood by older implementations of the eval loop (usually
@@ -231,7 +232,7 @@ def _write_atomic(path, data, mode=0o666):
231232
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
232233
# in PC/launcher.c must also be updated.
233234

234-
MAGIC_NUMBER = (3350).to_bytes(2, 'little') + b'\r\n'
235+
MAGIC_NUMBER = (3351).to_bytes(2, 'little') + b'\r\n'
235236
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
236237

237238
_PYCACHE = '__pycache__'

Lib/test/test_extcall.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
Traceback (most recent call last):
5858
...
5959
TypeError: f() got multiple values for keyword argument 'a'
60+
>>> f(1, 2, a=3, **{'a': 4}, **{'a': 5})
61+
Traceback (most recent call last):
62+
...
63+
TypeError: f() got multiple values for keyword argument 'a'
6064
>>> f(1, 2, 3, *[4, 5], **{'a':6, 'b':7})
6165
(1, 2, 3, 4, 5) {'a': 6, 'b': 7}
6266
>>> f(1, 2, 3, x=4, y=5, *(6, 7), **{'a':8, 'b': 9})

Lib/test/test_unpack_ex.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@
248248
...
249249
TypeError: f() got multiple values for keyword argument 'x'
250250
251+
>>> f(x=5, **{'x': 3}, **{'x': 2})
252+
Traceback (most recent call last):
253+
...
254+
TypeError: f() got multiple values for keyword argument 'x'
255+
251256
>>> f(**{1: 3}, **{1: 5})
252257
Traceback (most recent call last):
253258
...

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Release date: tba
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27286: Fixed compiling BUILD_MAP_UNPACK_WITH_CALL opcode. Calling
14+
function with generalized unpacking (PEP 448) and conflicting keyword names
15+
could cause undefined behavior.
16+
1317
- Issue #27066: Fixed SystemError if a custom opener (for open()) returns a
1418
negative number without setting an exception.
1519

PC/launcher.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ static PYC_MAGIC magic_values[] = {
10811081
{ 3160, 3180, L"3.2" },
10821082
{ 3190, 3230, L"3.3" },
10831083
{ 3250, 3310, L"3.4" },
1084-
{ 3320, 3350, L"3.5" },
1084+
{ 3320, 3351, L"3.5" },
10851085
{ 3360, 3361, L"3.6" },
10861086
{ 0 }
10871087
};

Python/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3262,7 +3262,7 @@ compiler_call_helper(struct compiler *c,
32623262
code |= 2;
32633263
if (nsubkwargs > 1) {
32643264
/* Pack it all up */
3265-
int function_pos = n + (code & 1) + nkw + 1;
3265+
int function_pos = n + (code & 1) + 2 * nkw + 1;
32663266
ADDOP_I(c, BUILD_MAP_UNPACK_WITH_CALL, nsubkwargs | (function_pos << 8));
32673267
}
32683268
}

Python/importlib_external.h

Lines changed: 104 additions & 104 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)