Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When creating a source from a file, there is no detection if its a named pipe #2467

Closed
vibbix opened this issue Oct 7, 2021 · 2 comments
Closed
Labels

Comments

@vibbix
Copy link

vibbix commented Oct 7, 2021

Bug report

Describe the bug
If i am writing an image to a named pipe, and try to open it with vips_source_new_from_file(filename) for IPC reasons, the call fails.

To Reproduce
Steps to reproduce the behavior:

  1. mkfifo /tmp/test-pipe
  2. create a Vips Source with vips_source_new_from_file
  3. result -1 & error

Expected behavior
The source should be similar to that of one created by vips_source_new_from_descriptor

Actual behavior
Creates the error above, resulting in:

vips__seek: unable to seek
unix error: Illegal seek

Environment

@vibbix vibbix added the bug label Oct 7, 2021
@jcupitt
Copy link
Member

jcupitt commented Oct 8, 2021

Hi @vibbix, thanks for the report.

Yes, I see this too. I tried this test program:

#!/usr/bin/python3

# try:
#   mkfifo /tmp/test-pipe
#   ./fifo.py /tmp/test-pipe x.jpg &
#   cat ~/pics/k2.jpg > /tmp/test-pipe

import sys
import pyvips

source = pyvips.Source.new_from_file(sys.argv[1])
image = pyvips.Image.new_from_source(source, "")

target = pyvips.Target.new_to_file(sys.argv[2])
image.write_to_target(target, ".jpg") 

I see:

$ ./fifo.py /tmp/test-pipe x.jpg &
[1] 589494
$ cat ~/pics/k2.jpg > /tmp/test-pipe
$ Traceback (most recent call last):
  File "/home/john/try/./fifo.py", line 11, in <module>
    source = pyvips.Source.new_from_file(sys.argv[1])
  File "/home/john/GIT/pyvips/pyvips/vsource.py", line 62, in new_from_file
    raise Error("can't create source from filename {0}"
pyvips.error.Error: can't create source from filename /tmp/test-pipe
  vips__seek: unable to seek
unix error: Illegal seek

It works if you use a file descriptor rather than a filename:

$ vipsthumbnail stdin < /tmp/test-pipe & 
[1] 568231
$ cat k2.jpg >/tmp/test-pipe
$ 
[1]+  Done                    vipsthumbnail stdin < /tmp/test-pipe
$ 

So I suppose (as you say) it's assuming named files are seekable, rather than testing for the capability.

jcupitt added a commit that referenced this issue Oct 8, 2021
We used to assume (in several places) that any source with a filename was
seekable. This patch adds a is_file test, and makes all the loaders use it.

see #2467
@jcupitt
Copy link
Member

jcupitt commented Oct 8, 2021

OK, fixed in master, this should all work now.

Thanks for finding this stupidity!

@jcupitt jcupitt closed this as completed Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants