patch from Brian Willoughby: fix handling of "offset" field in SSND chunk
authorJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 23 Sep 2004 00:23:16 +0000 (00:23 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 23 Sep 2004 00:23:16 +0000 (00:23 +0000)
src/flac/encode.c

index af6cba8..52fc9e2 100644 (file)
@@ -299,10 +299,6 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                        /* SSND chunk size */
                        if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        /* SSND chunk size */
                        if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
-                       else if(xx!=(sample_frames*bytes_per_frame + 8U)) {
-                               flac__utils_printf(stderr, 1, "%s: ERROR: SSND chunk size inconsistent with sample frame count\n", encoder_session.inbasefilename);
-                               return EncoderSession_finish_error(&encoder_session);
-                       }
                        data_bytes= xx;
                        pad= (data_bytes & 1U) ? true : false;
                        data_bytes-= 8U; /* discount the offset and block size fields */
                        data_bytes= xx;
                        pad= (data_bytes & 1U) ? true : false;
                        data_bytes-= 8U; /* discount the offset and block size fields */
@@ -310,11 +306,8 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                        /* offset */
                        if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        /* offset */
                        if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
-                       else if(xx!=0U) {
-                               flac__utils_printf(stderr, 1, "%s: ERROR: offset is %u; must be 0\n", encoder_session.inbasefilename, (unsigned int)xx);
-                               return EncoderSession_finish_error(&encoder_session);
-                       }
                        offset= xx;
                        offset= xx;
+                       data_bytes-= offset;
 
                        /* block size */
                        if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
 
                        /* block size */
                        if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
@@ -325,6 +318,15 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                        }
                        block_size= xx;
 
                        }
                        block_size= xx;
 
+                       if(fseek(infile, offset, SEEK_CUR)) {
+                               flac__utils_printf(stderr, 1, "%s: ERROR: skipping offset in SSND chunk\n", encoder_session.inbasefilename);
+                               return EncoderSession_finish_error(&encoder_session);
+                       }
+                       if(data_bytes!=(sample_frames*bytes_per_frame)) {
+                               flac__utils_printf(stderr, 1, "%s: ERROR: SSND chunk size inconsistent with sample frame count\n", encoder_session.inbasefilename);
+                               return EncoderSession_finish_error(&encoder_session);
+                       }
+
                        /* *options.common.align_reservoir_samples will be 0 unless --sector-align is used */
                        FLAC__ASSERT(options.common.sector_align || *options.common.align_reservoir_samples == 0);
                        total_samples_in_input = data_bytes / bytes_per_frame + *options.common.align_reservoir_samples;
                        /* *options.common.align_reservoir_samples will be 0 unless --sector-align is used */
                        FLAC__ASSERT(options.common.sector_align || *options.common.align_reservoir_samples == 0);
                        total_samples_in_input = data_bytes / bytes_per_frame + *options.common.align_reservoir_samples;