potential fix for zoom-related crash involving array overrun during peak generation
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 28 Oct 2009 21:02:28 +0000 (21:02 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 28 Oct 2009 21:02:28 +0000 (21:02 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@5960 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/audiosource.cc

index 36a667d1092342c1847b4c69bd4252dace5e401d..5bd9712762c206e8b9f84abbce2caa681f0f63b9 100644 (file)
@@ -523,21 +523,28 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, nframes_t npeaks, nframes_t s
 
                        if (i == frames_read) {
                                
-                               to_read = min (chunksize, (_length - current_frame));
+                               if (current_frame >= _length) {
 
-                               if (to_read == 0) {
-                                       /* XXX ARGH .. out by one error ... need to figure out why this happens
-                                          and fix it rather than do this band-aid move.
+                                       /* hmm, error condition - we've reached the end of the file
+                                          without generating all the peak data. cook up a zero-filled
+                                          data buffer and then use it. this is simpler than
+                                          adjusting zero_fill and npeaks and then breaking out of 
+                                          this loop early 
                                        */
-                                       zero_fill = npeaks - nvisual_peaks;
-                                       break;
-                               }
 
-                               if ((frames_read = read_unlocked (raw_staging, current_frame, to_read)) == 0) {
-                                       error << string_compose(_("AudioSource[%1]: peak read - cannot read %2 samples at offset %3 of %4 (%5)"),
-                                                               _name, to_read, current_frame, _length, strerror (errno)) 
-                                             << endmsg;
-                                       goto out;
+                                       memset (raw_staging, 0, sizeof (Sample) * chunksize);
+
+                               } else {
+                                       
+                                       to_read = min (chunksize, (_length - current_frame));
+                                       
+                                       
+                                       if ((frames_read = read_unlocked (raw_staging, current_frame, to_read)) == 0) {
+                                               error << string_compose(_("AudioSource[%1]: peak read - cannot read %2 samples at offset %3 of %4 (%5)"),
+                                                                       _name, to_read, current_frame, _length, strerror (errno)) 
+                                                     << endmsg;
+                                               goto out;
+                                       }
                                }
                                        
                                i = 0;