[easytag] Handle FLAC files with an invalid sample rate



commit 367e0b25f79a2e4cd8fa1a592f7093c13c6b748a
Author: David King <amigadave amigadave com>
Date:   Thu Nov 5 08:51:24 2015 +0000

    Handle FLAC files with an invalid sample rate
    
    Avoid dividing by zero when encountering FLAC files with a (invalid,
    according to the FLAC specification) sample rate of zero.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757547

 src/tags/flac_header.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/src/tags/flac_header.c b/src/tags/flac_header.c
index fee66b8..476aec4 100644
--- a/src/tags/flac_header.c
+++ b/src/tags/flac_header.c
@@ -108,11 +108,28 @@ et_flac_header_read_file_info (GFile *file,
 
         metadata_len += block->length;
 
-        if (block->type == FLAC__METADATA_TYPE_STREAMINFO)
+        if (FLAC__metadata_iterator_get_block_type (iter)
+            == FLAC__METADATA_TYPE_STREAMINFO)
         {
             const FLAC__StreamMetadata_StreamInfo *stream_info = &block->data.stream_info;
-            ETFileInfo->duration = stream_info->total_samples
-                                   / stream_info->sample_rate;
+            if (stream_info->sample_rate == 0)
+            {
+                gchar *filename;
+
+                /* This is invalid according to the FLAC specification, but
+                 * such files have been observed in the wild. */
+                ETFileInfo->duration = 0;
+
+                filename = g_file_get_path (file);
+                g_debug ("Invalid FLAC sample rate of 0: %s", filename);
+                g_free (filename);
+            }
+            else
+            {
+                ETFileInfo->duration = stream_info->total_samples
+                                       / stream_info->sample_rate;
+            }
+
             ETFileInfo->mode = stream_info->channels;
             ETFileInfo->samplerate = stream_info->sample_rate;
             ETFileInfo->version = 0; /* Not defined in FLAC file. */


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