ahupp / python-magic

A python wrapper for libmagic
Other
2.6k stars 280 forks source link

[Bug Report] Magic.from_file() chokes on pipe file #261

Closed Shad0 closed 1 year ago

Shad0 commented 2 years ago

The Magic class's fromfile() method begins with an elegant way of catching certain errors. Lines 110-113 in __init_\.py:

    def from_file(self, filename):
        # raise FileNotFoundException or IOError if the file does not exist
        with _real_open(filename):
            pass

_realopen() is just Python's builtin open() function. Lines 28-29 in __init_\.py:

# avoid shadowing the real open with the version from compat.py
_real_open = open

This causes a problem in an admittedly obscure situation: where the target file is a pipe file (mime type "inode/fifo"). The open() function opens the pipe for reading, and then sits there forever waiting for input that never comes. Which means from_file() also just sits there forever, never calling libmagic.magic_file() or returning any value or throwing any error.

(This is my first time reporting an issue on GitHub. Apologies if I've failed to follow the proper procedure!)

ahupp commented 1 year ago

Very sorry for the extremely slow response. This was fixed as a happy side effect of 722995466fda1451570c555e688819b75f1b8e65. Your issue report was fine :)