Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Tests/test_file_eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,22 @@ def test_image_mode_not_supported(tmp_path: Path) -> None:
im.save(tmpfile)


@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
def test_filename_not_parsed_as_ghostscript_argument(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
# Check that a filename starting with "-" is not passed to Ghostscript unmodified
# If it was, the help functionality would be triggered instead
monkeypatch.chdir(tmp_path)
name = "-h"
with open(name, "wb") as f:
f.write(b"\n".join(simple_eps_file))

with Image.open(name) as im:
im.load()
assert im.size == (100, 100)


@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
@skip_unless_feature("zlib")
def test_render_scale1() -> None:
Expand Down
5 changes: 4 additions & 1 deletion src/PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def Ghostscript(

infile_temp = None
if hasattr(fp, "name") and os.path.exists(fp.name):
infile = fp.name
# Make the path absolute so that a filename beginning with "-" or "@"
# can never be interpreted by Ghostscript's argument parser
# as an option or an @-file token
infile = os.path.abspath(fp.name)
else:
in_fd, infile_temp = tempfile.mkstemp()
os.close(in_fd)
Expand Down
Loading