Skip to content

Commit c712d68

Browse files
committed
Catch OSError when checking if fp is sys.stdout
1 parent 9b4fff8 commit c712d68

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/PIL/ImageFile.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,11 @@ def _save(im, fp, tile, bufsize=0):
493493
# But, it would need at least the image size in most cases. RawEncode is
494494
# a tricky case.
495495
bufsize = max(MAXBLOCK, bufsize, im.size[0] * 4) # see RawEncode.c
496-
if fp == sys.stdout or (hasattr(sys.stdout, "buffer") and fp == sys.stdout.buffer):
496+
try:
497+
stdout = fp == sys.stdout or fp == sys.stdout.buffer
498+
except (OSError, AttributeError):
499+
stdout = False
500+
if stdout:
497501
fp.flush()
498502
return
499503
try:

0 commit comments

Comments
 (0)