mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Avoid crash in call to magic_file() if the checked file does not exist
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40803 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d2f1b1a3df
commit
3929a71cd0
@ -375,32 +375,34 @@ string Formats::getFormatFromFile(FileName const & filename) const
|
||||
return string();
|
||||
|
||||
#ifdef HAVE_MAGIC_H
|
||||
magic_t magic_cookie = magic_open(MAGIC_MIME);
|
||||
if (magic_cookie) {
|
||||
string format;
|
||||
if (magic_load(magic_cookie, NULL) != 0) {
|
||||
LYXERR(Debug::GRAPHICS, "Formats::getFormatFromFile\n"
|
||||
<< "\tCouldn't load magic database - "
|
||||
<< magic_error(magic_cookie));
|
||||
} else {
|
||||
string mime = magic_file(magic_cookie,
|
||||
filename.toFilesystemEncoding().c_str());
|
||||
mime = token(mime, ';', 0);
|
||||
// we need our own ps/eps detection
|
||||
if (mime != "application/postscript") {
|
||||
Formats::const_iterator cit =
|
||||
find_if(formatlist.begin(), formatlist.end(),
|
||||
FormatMimeEqual(mime));
|
||||
if (cit != formats.end()) {
|
||||
LYXERR(Debug::GRAPHICS, "\tgot format from MIME type: "
|
||||
<< mime << " -> " << cit->name());
|
||||
format = cit->name();
|
||||
if (filename.exists()) {
|
||||
magic_t magic_cookie = magic_open(MAGIC_MIME);
|
||||
if (magic_cookie) {
|
||||
string format;
|
||||
if (magic_load(magic_cookie, NULL) != 0) {
|
||||
LYXERR(Debug::GRAPHICS, "Formats::getFormatFromFile\n"
|
||||
<< "\tCouldn't load magic database - "
|
||||
<< magic_error(magic_cookie));
|
||||
} else {
|
||||
string mime = magic_file(magic_cookie,
|
||||
filename.toFilesystemEncoding().c_str());
|
||||
mime = token(mime, ';', 0);
|
||||
// we need our own ps/eps detection
|
||||
if (mime != "application/postscript") {
|
||||
Formats::const_iterator cit =
|
||||
find_if(formatlist.begin(), formatlist.end(),
|
||||
FormatMimeEqual(mime));
|
||||
if (cit != formats.end()) {
|
||||
LYXERR(Debug::GRAPHICS, "\tgot format from MIME type: "
|
||||
<< mime << " -> " << cit->name());
|
||||
format = cit->name();
|
||||
}
|
||||
}
|
||||
}
|
||||
magic_close(magic_cookie);
|
||||
if (!format.empty())
|
||||
return format;
|
||||
}
|
||||
magic_close(magic_cookie);
|
||||
if (!format.empty())
|
||||
return format;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user