[easytag/wip/unstable] Improve TagLib error handling, bug 695453
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/unstable] Improve TagLib error handling, bug 695453
- Date: Sat, 4 Jan 2014 15:00:22 +0000 (UTC)
commit 5b873991803ec6dffdcf49b2553cda09e317dc70
Author: David King <amigadave amigadave com>
Date: Sun Mar 31 21:37:16 2013 +0100
Improve TagLib error handling, bug 695453
Avoid dereferencing NULL pointers returned from TagLib when an MP4 file
could not be read.
src/mp4_header.c | 12 +++++++++++-
src/mp4_tag.c | 37 ++++++++++++++++++++++++++++++++-----
2 files changed, 43 insertions(+), 6 deletions(-)
---
diff --git a/src/mp4_header.c b/src/mp4_header.c
index 370800c..8bb53d2 100644
--- a/src/mp4_header.c
+++ b/src/mp4_header.c
@@ -70,12 +70,22 @@ gboolean Mp4_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo)
if( !taglib_file_is_valid(file) )
{
gchar *filename_utf8 = filename_to_display(filename);
- Log_Print(LOG_ERROR,_("Error while opening file: '%s' (%s)."),filename_utf8,("Contains no audio
track"));
+ Log_Print (LOG_ERROR, _("File contains no audio track: '%s'"),
+ filename_utf8);
g_free(filename_utf8);
return FALSE;
}
properties = taglib_file_audioproperties(file);
+ if (properties == NULL)
+ {
+ gchar *filename_utf8 = filename_to_display (filename);
+ Log_Print (LOG_ERROR, _("Error reading properties from file: '%s'"),
+ filename_utf8);
+ g_free (filename_utf8);
+ taglib_file_free (file);
+ return FALSE;
+ }
/* Get format/subformat */
{
diff --git a/src/mp4_tag.c b/src/mp4_tag.c
index 738c1d7..a986c3a 100644
--- a/src/mp4_tag.c
+++ b/src/mp4_tag.c
@@ -85,8 +85,27 @@ gboolean Mp4tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
return FALSE;
}
- /* TODO Add error detection */
- tag = taglib_file_tag(mp4file);
+ /* Check for audio track */
+ if (!taglib_file_is_valid (mp4file))
+ {
+ gchar *filename_utf8 = filename_to_display (filename);
+ Log_Print (LOG_ERROR, _("File contains no audio track: '%s'"),
+ filename_utf8);
+ g_free (filename_utf8);
+ taglib_file_free (mp4file);
+ return FALSE;
+ }
+
+ tag = taglib_file_tag (mp4file);
+ if (tag == NULL)
+ {
+ gchar *filename_utf8 = filename_to_display (filename);
+ Log_Print (LOG_ERROR, _("Error reading tags from file: '%s'"),
+ filename_utf8);
+ g_free (filename_utf8);
+ taglib_file_free (mp4file);
+ return FALSE;
+ }
/*********
* Title *
@@ -173,8 +192,7 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
TagLib_Tag *tag;
gint error = 0;
- if (!ETFile || !ETFile->FileTag)
- return FALSE;
+ g_return_val_if_fail (ETFile != NULL || ETFile->FileTag != NULL, FALSE);
FileTag = (File_Tag *)ETFile->FileTag->data;
filename = ((File_Name *)ETFile->FileNameCur->data)->value;
@@ -196,7 +214,16 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
return FALSE;
}
- tag = taglib_file_tag(mp4file);
+ tag = taglib_file_tag (mp4file);
+ if (tag == NULL)
+ {
+ gchar *filename_utf8 = filename_to_display (filename);
+ Log_Print (LOG_ERROR, _("Error reading tags from file: '%s'"),
+ filename_utf8);
+ g_free (filename_utf8);
+ taglib_file_free (mp4file);
+ return FALSE;
+ }
/*********
* Title *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]