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

Skip to content

Commit e01b8a4

Browse files
Code review updates
1 parent 2b02b0c commit e01b8a4

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Arbitrary code in ``axes.prop_cycle`` rcParam strings
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33

4-
The ``axes.prop_cycle`` rcParam previously accepted arbitrary Python
5-
expressions by passing the string to ``eval()``. This is deprecated immediately
6-
without replacement for security reasons. The previously documented cycler
7-
operations at https://matplotlib.org/cycler/ are still supported.
4+
The ``axes.prop_cycle`` rcParam accepts Python expressions that are evaluated
5+
in a limited context. The evaluation context has been further limited and some
6+
expressions that previously worked (list comprehensions, for example) no longer
7+
will. This change is made without a deprecation period to improve security.
8+
The previously documented cycler operations at
9+
https://matplotlib.org/cycler/ are still supported.

doc/release/next_whats_new/cycler_rcparam_security.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
``axes.prop_cycle`` rcParam must be literal
2-
--------------------------------------------
1+
``axes.prop_cycle`` rcParam security improvements
2+
-------------------------------------------------
33

4-
The ``axes.prop_cycle`` rcParam is now parsed safely without ``eval()``. Only
5-
literal ``cycler()`` and ``concat()`` calls combined with ``+``, ``*``, and
6-
slicing are allowed. All previously valid cycler strings continue to work,
7-
for example:
4+
The ``axes.prop_cycle`` rcParam is now parsed in a safer and more restricted
5+
manner. Only literals, ``cycler()`` and ``concat()`` calls, the operators
6+
``+`` and ``*``, and slicing are allowed. All previously valid cycler strings
7+
documented at https://matplotlib.org/cycler/ are still supported, for example:
88

99
.. code-block:: none
1010

lib/matplotlib/tests/test_rcparams.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def generate_validator_testcases(valid):
276276
(cycler(mew=[2, 5]),
277277
cycler('markeredgewidth', [2, 5])),
278278
("2 * cycler('color', 'rgb')", 2 * cycler('color', 'rgb')),
279+
("2 * cycler('color', 'r' + 'gb')", 2 * cycler('color', 'rgb')),
279280
("cycler('color', 'rgb') * 2", cycler('color', 'rgb') * 2),
280281
("concat(cycler('color', 'rgb'), cycler('color', 'cmk'))",
281282
cycler('color', list('rgbcmk'))),
@@ -287,6 +288,8 @@ def generate_validator_testcases(valid):
287288
# cycler expressions are accepted.
288289
'fail': ((4, ValueError), # Gotta be a string or Cycler object
289290
('cycler("bleh, [])', ValueError), # syntax error
291+
("cycler('color', 'rgb') * * cycler('color', 'rgb')", # syntax error
292+
ValueError),
290293
('Cycler("linewidth", [1, 2, 3])',
291294
ValueError), # only 'cycler()' function is allowed
292295
# do not allow dunder in string literals

0 commit comments

Comments
 (0)