From b6fc1df022a0326e7c36122b1416061bf796c98f Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Tue, 1 Oct 2013 04:10:46 -0400 Subject: [PATCH] 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 --- gio/glocalfileinfo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index 0ba111075..c952d7562 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -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;