Discussion:
Magic MIME
(too old to reply)
Juri Linkov
2008-02-10 23:18:41 UTC
Permalink
Visiting an Arc Lisp file in Emacs fails with the error
"Buffer format not recognized".

Even though Emacs doesn't have an auto-mode-alist entry
associated with Arc, it should visit it in fundamental-mode,
not to fail trying to open it as an archive. Archive files
have a well-known signature, and using content-based file
type recognition rather than filename-based is more reliable.
This will also improve the recognition of image file formats.

Are there any obstacles to using magic-mime to determine the file
type in Emacs? If linking libmagic is not possible, then maybe
we could parse the magic.mime file, and even run the `file'
command directly on a visited file?
--
Juri Linkov
http://www.jurta.org/emacs/
Stefan Monnier
2008-02-11 02:24:30 UTC
Permalink
Post by Juri Linkov
not to fail trying to open it as an archive. Archive files
have a well-known signature, and using content-based file
type recognition rather than filename-based is more reliable.
C'mon Juri, you know better than that. We've been through it with the
image-recognition thingy, so it *should* be clear to everyone on this
list now that content based recognition is no better than filename-based
recognition (and vice versa). We need to use both.


Stefan
Juri Linkov
2008-02-11 20:55:33 UTC
Permalink
Post by Stefan Monnier
Post by Juri Linkov
not to fail trying to open it as an archive. Archive files
have a well-known signature, and using content-based file
type recognition rather than filename-based is more reliable.
C'mon Juri, you know better than that. We've been through it with the
image-recognition thingy, so it *should* be clear to everyone on this
list now that content based recognition is no better than filename-based
recognition (and vice versa). We need to use both.
Yes, I remember what a mess was the recognition of image files. But I think
that for other binary formats this could by simplified. If, say, a file
doesn't start with the "0x8080ffff 0x0000081a" signature there is no sense
to try treating it as an arc archive even if it has the .arc extension.

IIRC, the decision for the image file extensions taking precedence over
the image file content was based solely on the security holes that some
image libraries reportedly have. So that the user downloaded a .c file
somewhere from the Internet actually with an image inside should not take
the risk of opening it in image-mode in Emacs.

I don't know if such precautions are relevant for other binary formats
like archives.
--
Juri Linkov
http://www.jurta.org/emacs/
Stefan Monnier
2008-02-12 03:25:32 UTC
Permalink
Post by Juri Linkov
Yes, I remember what a mess was the recognition of image files. But I think
that for other binary formats this could by simplified. If, say, a file
doesn't start with the "0x8080ffff 0x0000081a" signature there is no sense
to try treating it as an arc archive even if it has the .arc extension.
Agreed. But just because a file starts with "0x8080ffff 0x0000081a"
shouldn't be enough of a reason to treat it as an arc archive: we need to
look at the filename as well.
Post by Juri Linkov
IIRC, the decision for the image file extensions taking precedence over
the image file content was based solely on the security holes that some
image libraries reportedly have.
I don't think so. I do remember that it was decided not to introduce
the two-sided (file-name and file-contents) method so close to
the release. So now would be a better time.

We could associate "\\.arc\\'" with '(lisp-arc-mode archive-mode)
and associate "0x8080ffff 0x0000081a" to archive-mode (and some other
pseudo-magic thingy for Arc-the-language).


Stefan
Eli Zaretskii
2008-02-11 04:16:25 UTC
Permalink
Date: Mon, 11 Feb 2008 01:18:41 +0200
Are there any obstacles to using magic-mime to determine the file
type in Emacs? If linking libmagic is not possible, then maybe
we could parse the magic.mime file, and even run the `file'
command directly on a visited file?
Whatever the decision is, please avoid relying in external commands
that are not available on all supported platforms. `file' isn't.

Emacs should be powerful enough to be able to visit files without
requiring an external tool; if it needs to consult some database for
that, it should be easy enough to include such a data base in the
Emacs distribution, perhaps even in a form that is convenient for
reading in Lisp.
Juri Linkov
2008-02-11 20:59:38 UTC
Permalink
Post by Eli Zaretskii
Post by Juri Linkov
Are there any obstacles to using magic-mime to determine the file
type in Emacs? If linking libmagic is not possible, then maybe
we could parse the magic.mime file, and even run the `file'
command directly on a visited file?
Whatever the decision is, please avoid relying in external commands
that are not available on all supported platforms. `file' isn't.
Emacs could follow the principle of graceful degradation here: if there
is no necessary external command or mime database on the system, then
it will provide less reliable result that will be no worse than the
current without using the magic.mime based file type recognition.
Post by Eli Zaretskii
Emacs should be powerful enough to be able to visit files without
requiring an external tool; if it needs to consult some database for
that, it should be easy enough to include such a data base in the
Emacs distribution, perhaps even in a form that is convenient for
reading in Lisp.
This is one option However, I'm not sure if licence conditions of the
mime-magic database allow including it to Emacs.
--
Juri Linkov
http://www.jurta.org/emacs/
Eli Zaretskii
2008-02-11 21:41:54 UTC
Permalink
Date: Mon, 11 Feb 2008 22:59:38 +0200
Post by Eli Zaretskii
Emacs should be powerful enough to be able to visit files without
requiring an external tool; if it needs to consult some database for
that, it should be easy enough to include such a data base in the
Emacs distribution, perhaps even in a form that is convenient for
reading in Lisp.
This is one option However, I'm not sure if licence conditions of the
mime-magic database allow including it to Emacs.
Even if the license precludes that, it can only prevent us from
including the data base verbatim. If we create our own data base,
with equivalent contents, but in utterly different form, no license
can prevent that, I think, especially if the person who writes that
data base for Emacs never looks at the original data base, but instead
works from a description written by someone else (that someone could
look at mime-magic to produce the description).
Richard Stallman
2008-02-12 03:51:02 UTC
Permalink
Emacs could follow the principle of graceful degradation here: if there
is no necessary external command or mime database on the system, then
it will provide less reliable result that will be no worse than the
current without using the magic.mime based file type recognition.

Unless that gets us big benefits, it is better if we don't use it.
There is an advantage in keeping Emacs self-contained.

Continue reading on narkive:
Search results for 'Magic MIME' (newsgroups and mailing lists)
39
replies
cvs commit: src/contrib/file-4 ChangeLog LEGAL.NOTICE MAINT README README.DELETED README.DRAGONFLY src/contrib/file-4/doc file.man libmagic.man magic.man src/contrib/file-4/magic Localstuff magic.mime src/contrib/file-4/magic/Magdir animation archive audio ...
started 2007-03-10 16:53:22 UTC
commits@dragonflybsd.org
7
replies
cvs commit: src/contrib/file-4 ChangeLog README.DRAGONFLY src/contrib/file-4/magic magic.mime src/contrib/file-4/magic/Magdir adventure apple archive audio bout compress console ctags digital gnu iff images java linux mach msdos riff sgi sharc sql ...
started 2005-07-04 01:13:40 UTC
commits@dragonflybsd.org
7
replies
cvs commit: src/contrib/file-4 ChangeLog README.DRAGONFLY src/contrib/file-4/doc file.man libmagic.man src/contrib/file-4/magic magic.mime src/contrib/file-4/magic/Magdir archive audio cad commands editors elf filesystems linux msdos ...
started 2006-12-04 02:39:57 UTC
commits@dragonflybsd.org
7
replies
cvs commit: src/contrib/file-4.12 src/contrib/file-4.12/doc src/contrib/file-4.12/magic src/contrib/file-4.12/magic/Magdir src/contrib/file-4.12/src
started 2004-12-15 18:26:11 UTC
commits@dragonflybsd.org
7
replies
cvs commit: src/contrib/file-4 ChangeLog src/contrib/file-4/doc libmagic.man magic.man src/contrib/file-4/magic magic.mime src/contrib/file-4/magic/Magdir archive audio console elf filesystems fonts images linux lisp msdos os400 revision ...
started 2007-05-28 05:23:18 UTC
commits@dragonflybsd.org
Loading...