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

Skip to content

Commit 089315c

Browse files
scottshambaughksunden
authored andcommitted
Code review updates
1 parent 2508393 commit 089315c

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/users/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
@@ -273,6 +273,7 @@ def generate_validator_testcases(valid):
273273
(cycler(mew=[2, 5]),
274274
cycler('markeredgewidth', [2, 5])),
275275
("2 * cycler('color', 'rgb')", 2 * cycler('color', 'rgb')),
276+
("2 * cycler('color', 'r' + 'gb')", 2 * cycler('color', 'rgb')),
276277
("cycler('color', 'rgb') * 2", cycler('color', 'rgb') * 2),
277278
("concat(cycler('color', 'rgb'), cycler('color', 'cmk'))",
278279
cycler('color', list('rgbcmk'))),
@@ -284,6 +285,8 @@ def generate_validator_testcases(valid):
284285
# cycler expressions are accepted.
285286
'fail': ((4, ValueError), # Gotta be a string or Cycler object
286287
('cycler("bleh, [])', ValueError), # syntax error
288+
("cycler('color', 'rgb') * * cycler('color', 'rgb')", # syntax error
289+
ValueError),
287290
('Cycler("linewidth", [1, 2, 3])',
288291
ValueError), # only 'cycler()' function is allowed
289292
# do not allow dunder in string literals

0 commit comments

Comments
 (0)