summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-10-01 08:10:46 (GMT)
committerMatthias Clasen <mclasen@redhat.com>2015-08-21 05:00:49 (GMT)
commitb6fc1df022a0326e7c36122b1416061bf796c98f (patch)
tree4758b728bd7662845687e72ce87404eeda8a79c2
parent8f662e72594acf8e7f874f7670d1421af68c7fc6 (diff)
downloadglib-b6fc1df022a0326e7c36122b1416061bf796c98f.zip
glib-b6fc1df022a0326e7c36122b1416061bf796c98f.tar.xz
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
-rw-r--r--gio/glocalfileinfo.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index 0ba1110..c952d75 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;