GLocalFileInfo: don't content-sniff zero-length files

This will prevent attempting to read from some files that appear normal but are
really device-like, such as those in /proc and /sys.

If we can't stat() the file then don't bother attempting to sniff, either.

https://bugzilla.gnome.org/show_bug.cgi?id=708525
This commit is contained in:
Ryan Lortie 2013-10-01 04:10:46 -04:00 committed by Matthias Clasen
parent 8f662e7259
commit b6fc1df022

View File

@ -1253,7 +1253,10 @@ get_content_type (const char *basename,
content_type = g_content_type_guess (basename, NULL, 0, &result_uncertain);
#ifndef G_OS_WIN32
if (!fast && result_uncertain && path != NULL)
/* Don't sniff zero-length files in order to avoid reading files
* that appear normal but are not (eg: files in /proc and /sys)
*/
if (!fast && result_uncertain && path != NULL && statbuf && statbuf->st_size != 0)
{
guchar sniff_buffer[4096];
gsize sniff_length;