ajlittoz has asked for the wisdom of the Perl Monks concerning the following question:
Hi wise monks,
I'm trying to use File::MMagic to filter non-text files in order to avoid further invalid UTF-8 sequences (I am aware this is not 100% bullet-proof if file uses another encoding).
I create a new instance, passing it the system 'magic' file, with
$magic = File::MMagic->new('/var/share/misc/magic');This the Fedora Linux location.
When I use it in
$magic->checktype_contents($buffer)File::MMagic emits a warning Bad offset/type at line 1 followed by a dump of the magic file.
This happens consistently across various Fedora versions, i.e. with Perl ranging from 5.8 to 5.22.
If I pass no file to method new, everything is OK. After investigating, the system magic file starts with an empty line. After removing this initial empty line, warning disappears.
Source for File::MMagic shows in sub readMagicEntry that empty lines should be silently ignored thanks to
$line =~ /^\s*$/This is effectively the case for non-initial empty lines (there are many in the magic file).
I have not checked what is and what is not initialized in $$MF[1] at beginning of magic file "compilation" as I solved my problem by making a private copy of the system file and removing the initial empty line.
My code runs in a server and exhibit the same behaviour under Apache/mod_perl or lighttpd/straight CGI.
Unless I made a mistake (I'm quite a newbee in Perl), this should be reported as a bug to the File::MMagic maintainer.
Regards,
ajl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::MMagic bug?
by stevieb (Canon) on Jan 16, 2016 at 22:43 UTC | |
by ajlittoz (Novice) on Jan 17, 2016 at 08:51 UTC |