From e8f63ec124e06c4098ed1ec763ad225871a063af Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Thu, 13 Oct 2011 16:38:26 +0200 Subject: [PATCH] The mime identification could potentially get a bad length exception while processing garbled "file" output --- src/index/mimetype.cpp | 5 +++++ 1 file changed, 5 insertions(+) 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