[glib] GLocalFileInfo: don't content-sniff zero-length files



commit b6fc1df022a0326e7c36122b1416061bf796c98f
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Oct 1 04:10:46 2013 -0400

    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 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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]