Skip to content

Commit 9734458

Browse files
committed
address reviews
1 parent 197dfa7 commit 9734458

File tree

5 files changed

+33
-26
lines changed

5 files changed

+33
-26
lines changed

Doc/library/pyexpat.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ XMLParser Objects
238238
.. versionadded:: 3.13
239239

240240

241-
:class:`!xmlparser` objects have the following methods to mitigate some
242-
common XML vulnerabilities.
241+
:class:`!xmlparser` objects have the following methods to tune protections
242+
against some common XML vulnerabilities.
243243

244244
.. method:: xmlparser.SetBillionLaughsAttackProtectionActivationThreshold(threshold, /)
245245

@@ -249,8 +249,8 @@ common XML vulnerabilities.
249249
The number of output bytes includes amplification from entity expansion
250250
and reading DTD files.
251251

252-
By default, parser objects have a protection activation threshold of 8 MiB,
253-
or equivalently 8,388,608 bytes.
252+
Parser objects usually have a protection activation threshold of 8 MiB,
253+
but the actual default value depends on the underlying Expat library.
254254

255255
An :exc:`ExpatError` is raised if this method is called on a
256256
|xml-non-root-parser| parser.
@@ -275,7 +275,8 @@ common XML vulnerabilities.
275275
benign files in practice. In particular, the activation threshold should be
276276
carefully chosen to avoid false positives.
277277

278-
By default, parser objects have a maximum amplification factor of 100.0.
278+
Parser objects usually have a maximum amplification factor of 100,
279+
but the actual default value depends on the underlying Expat library.
279280

280281
An :exc:`ExpatError` is raised if this method is called on a
281282
|xml-non-root-parser| parser or if *max_factor* is outside the valid range.
@@ -295,8 +296,8 @@ common XML vulnerabilities.
295296
Sets the number of allocated bytes of dynamic memory needed to activate
296297
protection against disproportionate use of RAM.
297298

298-
By default, parser objects have an allocation activation threshold of 64 MiB,
299-
or equivalently 67,108,864 bytes.
299+
Parser objects usually have an allocation activation threshold of 64 MiB,
300+
but the actual default value depends on the underlying Expat library.
300301

301302
An :exc:`ExpatError` is raised if this method is called on a
302303
|xml-non-root-parser| parser.
@@ -320,7 +321,8 @@ common XML vulnerabilities.
320321
near the start of parsing even with benign files in practice. In particular,
321322
the activation threshold should be carefully chosen to avoid false positives.
322323

323-
By default, parser objects have a maximum amplification factor of 100.0.
324+
Parser objects usually have a maximum amplification factor of 100,
325+
but the actual default value depends on the underlying Expat library.
324326

325327
An :exc:`ExpatError` is raised if this method is called on a
326328
|xml-non-root-parser| parser or if *max_factor* is outside the valid range.

Doc/whatsnew/3.15.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ xml.parsers.expat
564564

565565
* Add :meth:`~xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionActivationThreshold`
566566
and :meth:`~xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionMaximumAmplification`
567-
to :ref:`xmlparser <xmlparser-objects>` objects to tune `billion laughs`_ attacks protection.
567+
to :ref:`xmlparser <xmlparser-objects>` objects to tune protections against
568+
`billion laughs`_ attacks.
568569
(Contributed by Bénédikt Tran in :gh:`90949`.)
569570

570571
.. _billion laughs: https://en.wikipedia.org/wiki/Billion_laughs_attack

Misc/NEWS.d/next/Library/2025-09-26-18-04-28.gh-issue-90949.YHjSzX.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ Add
22
:meth:`~xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionActivationThreshold`
33
and
44
:meth:`~xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionMaximumAmplification`
5-
to :ref:`xmlparser <xmlparser-objects>` objects to mitigate `billion laughs
6-
<https://en.wikipedia.org/wiki/Billion_laughs_attack>`_ attacks. Patch by
7-
Bénédikt Tran.
5+
to :ref:`xmlparser <xmlparser-objects>` objects to tune protections against
6+
`billion laughs <https://en.wikipedia.org/wiki/Billion_laughs_attack>`_ attacks.
7+
Patch by Bénédikt Tran.

Modules/clinic/pyexpat.c.h

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/pyexpat.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,8 @@ pyexpat.xmlparser.SetBillionLaughsAttackProtectionActivationThreshold
12301230
12311231
Sets the number of output bytes needed to activate protection against billion laughs attacks.
12321232
1233-
By default, parser objects have a protection activation threshold of 8 MiB.
1233+
Parser objects usually have a protection activation threshold of 8 MiB,
1234+
but the actual default value depends on the underlying Expat library.
12341235
[clinic start generated code]*/
12351236

12361237
static PyObject *
@@ -1268,14 +1269,15 @@ or equal to 1.0. Amplification factors greater than 30,000 can be observed
12681269
in the middle of parsing even with benign files in practice. In particular,
12691270
the activation threshold should be carefully chosen to avoid false positives.
12701271
1271-
By default, parser objects have a maximum amplification factor of 100.0.
1272+
Parser objects usually have a maximum amplification factor of 100,
1273+
but the actual default value depends on the underlying Expat library.
12721274
[clinic start generated code]*/
12731275

12741276
static PyObject *
12751277
pyexpat_xmlparser_SetBillionLaughsAttackProtectionMaximumAmplification_impl(xmlparseobject *self,
12761278
PyTypeObject *cls,
12771279
float max_factor)
1278-
/*[clinic end generated code: output=c590439eadf463fa input=aec034366805f6c7]*/
1280+
/*[clinic end generated code: output=c590439eadf463fa input=c5bae55c9b25d045]*/
12791281
{
12801282
return set_maximum_amplification(
12811283
self, cls, max_factor,
@@ -1296,7 +1298,8 @@ pyexpat.xmlparser.SetAllocTrackerActivationThreshold
12961298
12971299
Sets the number of allocated bytes of dynamic memory needed to activate protection against disproportionate use of RAM.
12981300
1299-
By default, parser objects have an allocation activation threshold of 64 MiB.
1301+
Parser objects usually have an allocation activation threshold of 64 MiB,
1302+
but the actual default value depends on the underlying Expat library.
13001303
[clinic start generated code]*/
13011304

13021305
static PyObject *
@@ -1334,14 +1337,15 @@ or equal to 1.0. Amplification factors greater than 100.0 can be observed
13341337
near the start of parsing even with benign files in practice. In particular,
13351338
the activation threshold should be carefully chosen to avoid false positives.
13361339
1337-
By default, parser objects have a maximum amplification factor of 100.0.
1340+
Parser objects usually have a maximum amplification factor of 100,
1341+
but the actual default value depends on the underlying Expat library.
13381342
[clinic start generated code]*/
13391343

13401344
static PyObject *
13411345
pyexpat_xmlparser_SetAllocTrackerMaximumAmplification_impl(xmlparseobject *self,
13421346
PyTypeObject *cls,
13431347
float max_factor)
1344-
/*[clinic end generated code: output=6e44bd48c9b112a0 input=3544abf9dd7ae055]*/
1348+
/*[clinic end generated code: output=6e44bd48c9b112a0 input=aac2029e96e80b03]*/
13451349
{
13461350
return set_maximum_amplification(
13471351
self, cls, max_factor,

0 commit comments

Comments
 (0)