[mythtv] [patch] Fix crash in MythMusic CD ripper when dealing with invalid files.

J. Donavan Stanley jdonavan at gorpe.com
Thu Dec 4 06:02:31 EST 2003


As detailed in this message:
http://www.gossamer-threads.com/perl/mailarc/gforum.cgi?post=93071;search_string=mythmusic%20crash;guest=1704927&t=search_engine#93071

In a nutshell when ripCD creates and encoder to rip a track it assumes 
that the file the encoder creates is valid causing it to fail in 
ripTrack if it's not.  This patch adds an isValid function to the 
encoder that returns true if the file handle is non NULL.  RipCD checks 
isValid before calling ripTrack and bugs out of the whole ripping 
process if it gets false back.


-------------- next part --------------
Index: cdrip.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/cdrip.cpp,v
retrieving revision 1.35
diff -u -r1.35 cdrip.cpp
--- cdrip.cpp	28 Oct 2003 21:37:38 -0000	1.35
+++ cdrip.cpp	4 Dec 2003 10:49:44 -0000
@@ -489,7 +489,16 @@
                 encoder = new FlacEncoder(outfile, encodequal, track); 
             }
 
-            ripTrack(cddevice, encoder, trackno + 1);
+	    // Only try to rip the track if we have a valid encoder.
+	    // We should really show the user a warning dialog or something
+	    // but this stops us from crashing.
+	    if( !encoder->isValid() ) {
+		delete encoder;
+		delete track;
+		break;
+	    }
+		
+	    ripTrack(cddevice, encoder, trackno + 1);
 
             overall->setProgress(trackno + 1);
             qApp->processEvents();
Index: encoder.h
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/encoder.h,v
retrieving revision 1.2
diff -u -r1.2 encoder.h
--- encoder.h	10 Feb 2003 22:17:16 -0000	1.2
+++ encoder.h	4 Dec 2003 10:49:44 -0000
@@ -16,7 +16,7 @@
     Encoder(const QString &outfile, int qualitylevel, Metadata *metadata);
     virtual ~Encoder();
     virtual int addSamples(int16_t * bytes, unsigned int len) = 0;
-
+    virtual bool isValid() { return (out != NULL); }
   protected:
     const QString *outfile;
     FILE *out;


More information about the mythtv-dev mailing list