From: Josh Coalson Date: Fri, 5 Jan 2001 23:26:59 +0000 (+0000) Subject: fix to chop off bytes after end of data chunk X-Git-Tag: 1.2.0~2746 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=da68d764d8f36dc9a30127ff973a61df19d6773a;p=platform%2Fupstream%2Fflac.git fix to chop off bytes after end of data chunk --- diff --git a/src/flac/encode.c b/src/flac/encode.c index f4e6b2b..d67c4f8 100644 --- a/src/flac/encode.c +++ b/src/flac/encode.c @@ -239,18 +239,22 @@ int encode_wav(const char *infile, const char *outfile, bool verbose, uint64 ski else if(feof(fin)) break; } - else if(bytes_read % bytes_per_wide_sample != 0) { - fprintf(stderr, "ERROR, got partial sample from input file %s\n", infile); - goto wav_abort_; - } else { - unsigned wide_samples = bytes_read / bytes_per_wide_sample; - format_input(wide_samples, false, is_unsigned_samples, channels, bps, &encoder_wrapper); - if(!FLAC__encoder_process(encoder_wrapper.encoder, input, wide_samples)) { - fprintf(stderr, "ERROR during encoding, state = %d:%s\n", encoder_wrapper.encoder->state, FLAC__EncoderStateString[encoder_wrapper.encoder->state]); + if(bytes_read > data_bytes) + bytes_read = data_bytes; /* chop off anything after the end of the data chunk */ + if(bytes_read % bytes_per_wide_sample != 0) { + fprintf(stderr, "ERROR, got partial sample from input file %s\n", infile); goto wav_abort_; } - data_bytes -= bytes_read; + else { + unsigned wide_samples = bytes_read / bytes_per_wide_sample; + format_input(wide_samples, false, is_unsigned_samples, channels, bps, &encoder_wrapper); + if(!FLAC__encoder_process(encoder_wrapper.encoder, input, wide_samples)) { + fprintf(stderr, "ERROR during encoding, state = %d:%s\n", encoder_wrapper.encoder->state, FLAC__EncoderStateString[encoder_wrapper.encoder->state]); + goto wav_abort_; + } + data_bytes -= bytes_read; + } } }