On 14/07/2010 12:01, Christopher Key wrote:
When decoding a FLAC file with bits per sample that is not a multiple of 8 and outputting in raw format, the decoder gets as far as the write callback before realising that it doesn't know how to write the data. It then fails with an unhelpful message (or trips an assert() in debug mode). The attached patch performs the check earlier, and gives a more helpful error message.

Apologies for the immediate correction. The newly attached patch is probably somewhat safer, depending on whether libFLAC catches bps==0 || bps>=32 itself.
--- src/flac/decode.c.orig      2007-09-10 06:07:45.000000000 +0100
+++ src/flac/decode.c   2010-07-14 12:16:41.000000000 +0100
@@ -1245,10 +1245,19 @@
                        decoder_session->total_samples -= 
(metadata->data.stream_info.total_samples - until);
                }
 
-               if(decoder_session->bps < 4 || decoder_session->bps > 24) {
-                       flac__utils_printf(stderr, 1, "%s: ERROR: bits per 
sample is %u, must be 4-24\n", decoder_session->inbasefilename, 
decoder_session->bps);
-                       decoder_session->abort_flag = true;
-                       return;
+               if(decoder_session->analysis_mode || decoder_session->test_only 
|| decoder_session->is_wave_out || decoder_session->is_aiff_out) {
+                       if(decoder_session->bps < 4 || decoder_session->bps > 
24) {
+                               flac__utils_printf(stderr, 1, "%s: ERROR: bits 
per sample is %u, must be 4-24\n", decoder_session->inbasefilename, 
decoder_session->bps);
+                               decoder_session->abort_flag = true;
+                               return;
+                       }
+               }
+               else {
+                       if ((decoder_session->bps % 8) != 0  || 
decoder_session->bps < 4 || decoder_session->bps > 24) {
+                               flac__utils_printf(stderr, 1, "%s: ERROR: bits 
per sample is %u, must be 8/16/24 for raw format output\n", 
decoder_session->inbasefilename, decoder_session->bps);
+                               decoder_session->abort_flag = true;
+                               return;
+                       }
                }
        }
        else if(metadata->type == FLAC__METADATA_TYPE_CUESHEET) {
_______________________________________________
Flac-dev mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/flac-dev

Reply via email to