Commit 03b4a7f1 authored by Mikael Ottela's avatar Mikael Ottela

Added checks for minimum file size and access

svn path=/trunk/; revision=2922
parent 288f7e84
2009-02-12 Mikael Ottela <mikael.ottela@ixonos.com>
* src/tracker-extract/tracker-main.c
* src/tracker-extract/tracker-extract-jpeg.c
* src/tracker-extract/tracker-extract-png.c: Added checks for
minimum file size and access.
Fixes NB #101096.
2009-02-11 Mikael Ottela <mikael.ottela@ixonos.com>
* src/libtracker-data/tracker-data-schema.c
......
......@@ -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 @@ static void
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 @@ extract_jpeg (const gchar *filename,
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;
......
......@@ -141,6 +141,9 @@ static void
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 @@ extract_png (const gchar *filename,
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,
......
......@@ -132,7 +132,7 @@ main (int argc, char *argv[])
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"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment