Skip to content

Commit 6810ca8

Browse files
committed
Fix TexManager's support for openout_any = p
The "paranoid" default of Kpathsea (TeX Live's path resolution system) disallows access to parent directories.
1 parent 25b39d4 commit 6810ca8

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/matplotlib/tests/test_texmanager.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import os
12
from pathlib import Path
23
import re
4+
import subprocess
5+
import sys
36

47
import matplotlib.pyplot as plt
58
from matplotlib.texmanager import TexManager
@@ -57,3 +60,15 @@ def test_unicode_characters():
5760
with pytest.raises(RuntimeError):
5861
ax.set_title('\N{SNOWMAN}')
5962
fig.canvas.draw()
63+
64+
65+
@needs_usetex
66+
def test_openin_any_paranoid():
67+
completed = subprocess.run(
68+
[sys.executable, "-c",
69+
'import matplotlib.pyplot as plt;'
70+
'plt.rcParams.update({"text.usetex": True});'
71+
'plt.plot("paranoid");'
72+
'plt.show(block=False);'],
73+
env={**os.environ, 'openin_any': 'p'}, check=True, capture_output=True)
74+
assert completed.stderr == b""

lib/matplotlib/texmanager.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,16 @@ def make_dvi(cls, tex, fontsize):
291291
# and thus replace() works atomically. It also allows referring to
292292
# the texfile with a relative path (for pathological MPLCONFIGDIRs,
293293
# the absolute path may contain characters (e.g. ~) that TeX does
294-
# not support.)
295-
with TemporaryDirectory(dir=Path(dvifile).parent) as tmpdir:
294+
# not support; n.b. relative paths cannot traverse parents, or it
295+
# will be blocked when `openin_any = p` in texmf.cnf).
296+
cwd = Path(dvifile).parent
297+
with TemporaryDirectory(dir=cwd) as tmpdir:
298+
tmppath = Path(tmpdir)
296299
cls._run_checked_subprocess(
297300
["latex", "-interaction=nonstopmode", "--halt-on-error",
298-
f"../{texfile.name}"], tex, cwd=tmpdir)
299-
(Path(tmpdir) / Path(dvifile).name).replace(dvifile)
301+
f"--output-directory={tmppath.name}",
302+
f"{texfile.name}"], tex, cwd=cwd)
303+
(tmppath / Path(dvifile).name).replace(dvifile)
300304
return dvifile
301305

302306
@classmethod

0 commit comments

Comments
 (0)