Skip to content

Commit 046dc95

Browse files
committed
Merge remote-tracking branch 'upstream/main' into fix-mimetypes-case-sensitive-add-type
2 parents 4886f13 + 4084141 commit 046dc95

16 files changed

Lines changed: 73 additions & 34 deletions

Doc/howto/functional.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ first calculation. ::
10421042
>>> functools.reduce(operator.concat, [])
10431043
Traceback (most recent call last):
10441044
...
1045-
TypeError: reduce() of empty sequence with no initial value
1045+
TypeError: reduce() of empty iterable with no initial value
10461046
>>> functools.reduce(operator.mul, [1, 2, 3], 1)
10471047
6
10481048
>>> functools.reduce(operator.mul, [], 1)

Doc/library/stdtypes.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,8 @@ expression support in the :mod:`re` module).
23762376

23772377
Return a copy of the string with leading characters removed. The *chars*
23782378
argument is a string specifying the set of characters to be removed. If omitted
2379-
or ``None``, the *chars* argument defaults to removing whitespace. The *chars*
2379+
or ``None``, the *chars* argument defaults to removing whitespace, that is
2380+
characters for which :meth:`str.isspace` is true. The *chars*
23802381
argument is not a prefix; rather, all combinations of its values are stripped::
23812382

23822383
>>> ' spacious '.lstrip()
@@ -2579,7 +2580,8 @@ expression support in the :mod:`re` module).
25792580

25802581
Return a copy of the string with trailing characters removed. The *chars*
25812582
argument is a string specifying the set of characters to be removed. If omitted
2582-
or ``None``, the *chars* argument defaults to removing whitespace. The *chars*
2583+
or ``None``, the *chars* argument defaults to removing whitespace, that is
2584+
characters for which :meth:`str.isspace` is true. The *chars*
25832585
argument is not a suffix; rather, all combinations of its values are stripped.
25842586
For example:
25852587

@@ -2755,11 +2757,9 @@ expression support in the :mod:`re` module).
27552757

27562758
Return a copy of the string with the leading and trailing characters removed.
27572759
The *chars* argument is a string specifying the set of characters to be removed.
2758-
If omitted or ``None``, the *chars* argument defaults to removing whitespace.
2759-
The *chars* argument is not a prefix or suffix; rather, all combinations of its
2760-
values are stripped.
2761-
2762-
Whitespace characters are defined by :meth:`str.isspace`.
2760+
If omitted or ``None``, the *chars* argument defaults to removing whitespace,
2761+
that is characters for which :meth:`str.isspace` is true. The *chars* argument
2762+
is not a prefix or suffix; rather, all combinations of its values are stripped.
27632763

27642764
For example:
27652765

Lib/shutil.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,12 +1307,6 @@ def unregister_unpack_format(name):
13071307
"""Removes the pack format from the registry."""
13081308
del _UNPACK_FORMATS[name]
13091309

1310-
def _ensure_directory(path):
1311-
"""Ensure that the parent directory of `path` exists"""
1312-
dirname = os.path.dirname(path)
1313-
if not os.path.isdir(dirname):
1314-
os.makedirs(dirname)
1315-
13161310
def _unpack_zipfile(filename, extract_dir):
13171311
"""Unpack zip `filename` to `extract_dir`
13181312
"""

Lib/test/test_bz2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,21 @@ def test_failure(self):
10321032
# Previously, a second call could crash due to internal inconsistency
10331033
self.assertRaises(Exception, bzd.decompress, self.BAD_DATA * 30)
10341034

1035+
def test_decompress_after_data_error(self):
1036+
data = bytes.fromhex(
1037+
"425a6839314159265359000000000000007fffff000000000000000000000000"
1038+
"00000000000000000000000000000000000000e0370000000000000000000000"
1039+
"000000000000000000000000000000000000000000000000000083f3"
1040+
)
1041+
bzd = BZ2Decompressor()
1042+
with self.assertRaisesRegex(OSError, "Invalid data stream"):
1043+
bzd.decompress(data)
1044+
# Previously, a second call could crash due to internal inconsistency
1045+
self.assertFalse(bzd.needs_input)
1046+
self.assertFalse(bzd.eof)
1047+
with self.assertRaisesRegex(ValueError, "previous error"):
1048+
bzd.decompress(b'\x00' * 18)
1049+
10351050
@support.refcount_test
10361051
def test_refleaks_in___init__(self):
10371052
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')

Lib/test/test_mmap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ def test_find_end(self):
354354
self.assertEqual(m.find(b'one', 1, -1), 8)
355355
self.assertEqual(m.find(b'one', 1, -2), -1)
356356
self.assertEqual(m.find(bytearray(b'one')), 0)
357+
self.assertEqual(m.find(b'', n + 1), -1)
358+
self.assertEqual(m.rfind(b'', n + 1), -1)
357359

358360
for i in range(-n-1, n+1):
359361
for j in range(-n-1, n+1):

Lib/test/test_xmlrpc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ def test_dump_encoding(self):
208208
self.assertEqual(xmlrpclib.loads(strg)[0][0], value)
209209
self.assertEqual(xmlrpclib.loads(strg)[1], methodname)
210210

211+
def test_dump_escape_methodname(self):
212+
payload = 'foo</methodName><injected attr="evil"/><methodName>bar'
213+
s = xmlrpclib.dumps((), methodname=payload)
214+
self.assertIn(
215+
'<methodName>foo&lt;/methodName&gt;&lt;injected attr="evil"/&gt;'
216+
'&lt;methodName&gt;bar</methodName>', s
217+
)
218+
self.assertNotIn('<injected attr="evil"/>', s)
219+
load, m = xmlrpclib.loads(s)
220+
self.assertEqual(m, payload)
221+
211222
def test_dump_bytes(self):
212223
sample = b"my dog has fleas"
213224
self.assertEqual(sample, xmlrpclib.Binary(sample))

Lib/xmlrpc/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None,
965965
data = (
966966
xmlheader,
967967
"<methodCall>\n"
968-
"<methodName>", methodname, "</methodName>\n",
968+
"<methodName>", escape(methodname), "</methodName>\n",
969969
data,
970970
"</methodCall>\n"
971971
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Speed up frame local variable item collection by appending result pairs to the
2+
output list without an extra reference-count round-trip (using the internal
3+
reference-stealing list append helper). Patch by Omkar Kabde.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix XML injection vulnerability in :func:`xmlrpc.client.dumps` where the ``methodname`` was not being escaped before interpolation into the XML body.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Speed up :func:`re.findall`, :func:`re.sub` and :func:`re.subn` by appending
2+
result items to the output list without an extra reference-count round-trip
3+
(using the internal reference-stealing list append helper).

0 commit comments

Comments
 (0)