Raise FileNotFoundError when opening an empty path by radarhere · Pull Request #9048 · python-pillow/Pillow

Skip to content

Navigation Menu

Sign in

Appearance settings

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Conversation

@radarhere

Copy link Copy Markdown

Member

Resolves #9047

The following code didn't consider the possibility of an empty filename being passed in by the user, and tries to treat it as a file handle instead.

Pillow/src/PIL/Image.py

Lines 3510 to 3518 in 2b39f75

filename: str | bytes = ""
if is_path(fp):
filename = os.fspath(fp)
if filename:
fp = builtins.open(filename, "rb")
exclusive_fp = True
else:
fp = cast(IO[bytes], fp)

This fixes that.

senyai reacted with heart emoji

@hugovk hugovk merged commit 84855d1 into python-pillow:main

Jun 30, 2025

57 checks passed

@radarhere radarhere deleted the empty_path branch

June 30, 2025 22:27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Inconsistent Image.open(str)

2 participants

@radarhere @hugovk