tracker r2922 - in trunk: . src/tracker-extract



Author: mottela
Date: Thu Feb 12 08:06:51 2009
New Revision: 2922
URL: http://svn.gnome.org/viewvc/tracker?rev=2922&view=rev

Log:
Added checks for minimum file size and access

Modified:
   trunk/ChangeLog
   trunk/src/tracker-extract/tracker-extract-jpeg.c
   trunk/src/tracker-extract/tracker-extract-png.c
   trunk/src/tracker-extract/tracker-main.c

Modified: trunk/src/tracker-extract/tracker-extract-jpeg.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-jpeg.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-jpeg.c	Thu Feb 12 08:06:51 2009
@@ -20,7 +20,7 @@
  */
 
 /*
- * FIXME: Use EXIF_DATA_OPTION_FOLLOW_SPECIFICATION for libexif to get raw data.
+ * FIXME: We should try to get raw data (from libexif) to avoid processing.
  */
 
 #include "config.h"
@@ -247,6 +247,9 @@
 extract_jpeg (const gchar *filename,
 	      GHashTable  *metadata)
 {
+	struct stat  fstatbuf;
+	size_t	     size;
+
 	struct jpeg_decompress_struct  cinfo;
 	struct jpeg_error_mgr	       jerr;
 	struct jpeg_marker_struct     *marker;
@@ -257,6 +260,18 @@
 		return;
 	}
 
+	if (stat (filename, &fstatbuf) == -1) {
+		close(fd_jpeg);
+		return;
+	}
+
+	/* Check size at least SOI+JFIF without thumb */
+	size = fstatbuf.st_size;
+	if (size < 18) {
+		close (fd_jpeg);
+		return;
+	}
+
 	if ((jpeg = fdopen (fd_jpeg, "rb"))) {
 		gchar *str;
 		gsize  len;

Modified: trunk/src/tracker-extract/tracker-extract-png.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-png.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-png.c	Thu Feb 12 08:06:51 2009
@@ -141,6 +141,9 @@
 extract_png (const gchar *filename,
 	     GHashTable  *metadata)
 {
+	struct stat  fstatbuf;
+	size_t	     size;
+
 	gint	     fd_png;
 	FILE	    *png;
 	png_structp  png_ptr;
@@ -154,13 +157,26 @@
 	gint	     interlace_type, compression_type, filter_type;
 
 #if defined(__linux__)
-	if ((fd_png = g_open (filename, (O_RDONLY | O_NOATIME))) == -1) {
+	if (((fd_png = g_open (filename, (O_RDONLY | O_NOATIME))) == -1) &&
+	    ((fd_png = g_open (filename, (O_RDONLY))) == -1 ) ) {
 #else
 	if ((fd_png = g_open (filename, O_RDONLY)) == -1) {
 #endif
 		return;
 	}
 
+	if (stat (filename, &fstatbuf) == -1) {
+		close(fd_png);
+		return;
+	}
+
+	/* Check for minimum header size */
+	size = fstatbuf.st_size;
+	if (size < 64) {
+		close (fd_png);
+		return;
+	}
+
 	if ((png = fdopen (fd_png, "r"))) {
 		png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
 						  NULL,

Modified: trunk/src/tracker-extract/tracker-main.c
==============================================================================
--- trunk/src/tracker-extract/tracker-main.c	(original)
+++ trunk/src/tracker-extract/tracker-main.c	Thu Feb 12 08:06:51 2009
@@ -132,7 +132,7 @@
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 	textdomain (GETTEXT_PACKAGE);
 
-	/* Translators: this messagge will apper immediately after the	*/
+	/* Translators: this message will appear immediately after the	*/
 	/* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>	*/
 	context = g_option_context_new (_("- Extract file meta data"));
 



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