Skip to content

Commit 8ab4175

Browse files
committed
Merge remote-tracking branch 'origin/main' into android-ram
2 parents 83c0985 + dea4083 commit 8ab4175

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2807
-1532
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,16 @@ jobs:
206206
strategy:
207207
fail-fast: false
208208
matrix:
209-
# macos-26 is Apple Silicon, macos-26-intel is Intel.
210-
# macos-26-intel only runs tests against the GIL-enabled CPython.
209+
# macos-26 is Apple Silicon, macos-15-intel is Intel.
210+
# macos-15-intel only runs tests against the GIL-enabled CPython.
211211
os:
212212
- macos-26
213-
- macos-26-intel
213+
- macos-15-intel
214214
free-threading:
215215
- false
216216
- true
217217
exclude:
218-
- os: macos-26-intel
218+
- os: macos-15-intel
219219
free-threading: true
220220
uses: ./.github/workflows/reusable-macos.yml
221221
with:

.github/workflows/reusable-macos.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ jobs:
5252
--prefix=/opt/python-dev \
5353
--with-openssl="$(brew --prefix openssl@3.5)"
5454
- name: Build CPython
55-
if : ${{ inputs.free-threading || inputs.os != 'macos-26-intel' }}
55+
if : ${{ inputs.free-threading || inputs.os != 'macos-15-intel' }}
5656
run: gmake -j8
5757
- name: Build CPython for compiler warning check
58-
if : ${{ !inputs.free-threading && inputs.os == 'macos-26-intel' }}
58+
if : ${{ !inputs.free-threading && inputs.os == 'macos-15-intel' }}
5959
run: set -o pipefail; gmake -j8 --output-sync 2>&1 | tee compiler_output_macos.txt
6060
- name: Display build info
6161
run: make pythoninfo
6262
- name: Check compiler warnings
63-
if : ${{ !inputs.free-threading && inputs.os == 'macos-26-intel' }}
63+
if : ${{ !inputs.free-threading && inputs.os == 'macos-15-intel' }}
6464
run: >-
6565
python3 Tools/build/check_warnings.py
6666
--compiler-output-file-path=compiler_output_macos.txt

Doc/conf.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,17 @@
572572
stable_abi_file = 'data/stable_abi.dat'
573573
threadsafety_file = 'data/threadsafety.dat'
574574

575+
# Options for notfound.extension
576+
# -------------------------------
577+
578+
if not os.getenv("READTHEDOCS"):
579+
if language_code:
580+
notfound_urls_prefix = (
581+
f'/{language_code.replace("_", "-").lower()}/{version}/'
582+
)
583+
else:
584+
notfound_urls_prefix = f'/{version}/'
585+
575586
# Options for sphinxext-opengraph
576587
# -------------------------------
577588

Doc/howto/remote_debugging.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,3 +624,58 @@ To inject and execute a Python script in a remote process:
624624
6. Set ``_PY_EVAL_PLEASE_STOP_BIT`` in the ``eval_breaker`` field.
625625
7. Resume the process (if suspended). The script will execute at the next safe
626626
evaluation point.
627+
628+
.. _remote-debugging-threat-model:
629+
630+
Security and threat model
631+
=========================
632+
633+
The remote debugging protocol relies on the same operating system primitives
634+
used by native debuggers such as GDB and LLDB. Attaching to a process
635+
requires the **same privileges** that those debuggers require, for example
636+
``ptrace`` / Yama LSM on Linux, ``task_for_pid`` on macOS, and
637+
``SeDebugPrivilege`` on Windows. Python does not introduce any new privilege
638+
escalation path; if an attacker already possesses the permissions needed to
639+
attach to a process, they could equally use GDB to read memory or inject
640+
code.
641+
642+
The following principles define what is, and is not, considered a security
643+
vulnerability in this feature:
644+
645+
Attaching requires OS-level privileges
646+
On every supported platform the operating system gates cross-process
647+
memory access behind privilege checks (``CAP_SYS_PTRACE``, root, or
648+
administrator rights). A report that demonstrates an issue only after
649+
these privileges have already been obtained is **not** a vulnerability in
650+
CPython, since the OS security boundary was already crossed.
651+
652+
Crashes or memory errors when reading a compromised process are not vulnerabilities
653+
A tool that reads internal interpreter state from a target process must
654+
trust that memory to be well-formed. If the target process has been
655+
corrupted or is controlled by an attacker, the debugger or profiler may
656+
crash, produce garbage output, or behave unpredictably. This is the same
657+
risk accepted by every ``ptrace``-based debugger. Bugs in this category
658+
(buffer overflows, segmentation faults, or undefined behaviour triggered
659+
by reading corrupted state) are **not** treated as security issues, though
660+
fixes that improve robustness are welcome.
661+
662+
Vulnerabilities in the target process are not in scope
663+
If the Python process being debugged has already been compromised, the
664+
attacker already controls execution in that process. Demonstrating further
665+
impact from that starting point does not constitute a vulnerability in the
666+
remote debugging protocol.
667+
668+
When to use ``PYTHON_DISABLE_REMOTE_DEBUG``
669+
-------------------------------------------
670+
671+
The environment variable :envvar:`PYTHON_DISABLE_REMOTE_DEBUG` (and the
672+
equivalent :option:`-X disable_remote_debug` flag) allows operators to disable
673+
the in-process side of the protocol as a **defence-in-depth** measure. This
674+
may be useful in hardened or sandboxed deployment environments where no
675+
debugging or profiling of the process is expected and reducing attack surface
676+
is a priority, even though the OS-level privilege checks already prevent
677+
unprivileged access.
678+
679+
Setting this variable does **not** affect other OS-level debugging interfaces
680+
(``ptrace``, ``/proc``, ``task_for_pid``, etc.), which remain available
681+
according to their own permission models.

Doc/library/argparse.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,15 @@ User defined functions can be used as well:
11181118

11191119
The :func:`bool` function is not recommended as a type converter. All it does
11201120
is convert empty strings to ``False`` and non-empty strings to ``True``.
1121-
This is usually not what is desired.
1121+
This is usually not what is desired::
1122+
1123+
>>> parser = argparse.ArgumentParser()
1124+
>>> _ = parser.add_argument('--verbose', type=bool)
1125+
>>> parser.parse_args(['--verbose', 'False'])
1126+
Namespace(verbose=True)
1127+
1128+
See :class:`BooleanOptionalAction` or ``action='store_true'`` for common
1129+
alternatives.
11221130

11231131
In general, the ``type`` keyword is a convenience that should only be used for
11241132
simple conversions that can only raise one of the three supported exceptions.

Doc/library/http.server.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ instantiation, of which this module provides three different variants:
287287
specifying its value. Note that, after the send_header calls are done,
288288
:meth:`end_headers` MUST BE called in order to complete the operation.
289289

290+
This method does not reject input containing CRLF sequences.
291+
290292
.. versionchanged:: 3.2
291293
Headers are stored in an internal buffer.
292294

@@ -297,6 +299,8 @@ instantiation, of which this module provides three different variants:
297299
buffered and sent directly the output stream.If the *message* is not
298300
specified, the HTTP message corresponding the response *code* is sent.
299301

302+
This method does not reject *message* containing CRLF sequences.
303+
300304
.. versionadded:: 3.2
301305

302306
.. method:: end_headers()
@@ -555,6 +559,11 @@ Security considerations
555559
requests, this makes it possible for files outside of the specified directory
556560
to be served.
557561

562+
Methods :meth:`BaseHTTPRequestHandler.send_header` and
563+
:meth:`BaseHTTPRequestHandler.send_response_only` assume sanitized input
564+
and does not perform input validation such as checking for the presence of CRLF
565+
sequences. Untrusted input may result in HTTP Header injection attacks.
566+
558567
Earlier versions of Python did not scrub control characters from the
559568
log messages emitted to stderr from ``python -m http.server`` or the
560569
default :class:`BaseHTTPRequestHandler` ``.log_message``

Doc/library/timeit.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,24 @@ The module defines three convenience functions and a public class:
143143
timeit.Timer('for i in range(10): oct(i)', 'gc.enable()').timeit()
144144

145145

146-
.. method:: Timer.autorange(callback=None)
146+
.. method:: Timer.autorange(callback=None, target_time=None)
147147

148148
Automatically determine how many times to call :meth:`.timeit`.
149149

150150
This is a convenience function that calls :meth:`.timeit` repeatedly
151-
so that the total time >= 0.2 second, returning the eventual
151+
so that the total time >= *Timer.target_time* seconds, returning the eventual
152152
(number of loops, time taken for that number of loops). It calls
153153
:meth:`.timeit` with increasing numbers from the sequence 1, 2, 5,
154-
10, 20, 50, ... until the time taken is at least 0.2 seconds.
154+
10, 20, 50, ... until the time taken is at least *target_time* seconds.
155155

156156
If *callback* is given and is not ``None``, it will be called after
157157
each trial with two arguments: ``callback(number, time_taken)``.
158158

159159
.. versionadded:: 3.6
160160

161+
.. versionchanged:: next
162+
The optional *target_time* parameter was added.
163+
161164

162165
.. method:: Timer.repeat(repeat=5, number=1000000)
163166

@@ -239,6 +242,13 @@ Where the following options are understood:
239242

240243
.. versionadded:: 3.5
241244

245+
.. option:: -t, --target-time=T
246+
247+
if :option:`--number` is 0, the code will run until it takes at
248+
least this many seconds (default: 0.2)
249+
250+
.. versionadded:: next
251+
242252
.. option:: -v, --verbose
243253

244254
print raw timing results; repeat for more digits precision
@@ -254,7 +264,7 @@ similarly.
254264

255265
If :option:`-n` is not given, a suitable number of loops is calculated by trying
256266
increasing numbers from the sequence 1, 2, 5, 10, 20, 50, ... until the total
257-
time is at least 0.2 seconds.
267+
time is at least :option:`--target-time` seconds (default: 0.2).
258268

259269
:func:`default_timer` measurements can be affected by other programs running on
260270
the same machine, so the best thing to do when accurate timing is necessary is

Doc/whatsnew/3.15.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,11 @@ timeit
10901090
:ref:`environment variables <using-on-controlling-color>`.
10911091
(Contributed by Yi Hong in :gh:`139374`.)
10921092

1093+
* Make the target time of :meth:`timeit.Timer.autorange` configurable
1094+
and add ``--target-time`` option to the command-line interface.
1095+
(Contributed by Alessandro Cucci and Miikka Koskinen in :gh:`140283`.)
1096+
1097+
10931098
tkinter
10941099
-------
10951100

Include/cpython/pystats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ typedef struct _optimization_stats {
144144
uint64_t unknown_callee;
145145
uint64_t trace_immediately_deopts;
146146
uint64_t executors_invalidated;
147+
uint64_t fitness_terminated_traces;
147148
UOpStats opcode[PYSTATS_MAX_UOP_ID + 1];
148149
uint64_t unsupported_opcode[256];
149150
uint64_t trace_length_hist[_Py_UOP_HIST_SIZE];

Include/internal/pycore_interp_structs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,10 @@ typedef struct _PyOptimizationConfig {
449449
uint16_t side_exit_initial_value;
450450
uint16_t side_exit_initial_backoff;
451451

452+
// Trace fitness thresholds
453+
uint16_t fitness_initial;
454+
uint16_t fitness_initial_side;
455+
452456
// Optimization flags
453457
bool specialization_enabled;
454458
bool uops_optimize_enabled;

0 commit comments

Comments
 (0)