diff --git a/src/index/mimetype.cpp b/src/index/mimetype.cpp index e02a1b13..edf36eaf 100644 --- a/src/index/mimetype.cpp +++ b/src/index/mimetype.cpp @@ -74,6 +74,11 @@ static string mimetypefromdata(const string &fn, bool usfc) // The result of 'file' execution begins with the file name // which may contain spaces. We happen to know its size, so // strip it: + if (result.size() <= fn.size()) { + // Garbage "file" output. Maybe the result of a charset + // conversion attempt? + return string(); + } result = result.substr(fn.size()); // Now looks like ": text/plain; charset=us-ascii" // Split it, and take second field