Warn for data trailing the data chunk
This commit is contained in:
parent
29b57b59a4
commit
a87e6ba5f4
@ -1063,6 +1063,25 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
|
||||
case FORMAT_AIFF_C:
|
||||
/* truncation in the division removes any padding byte that was counted in encoder_session.fmt.iff.data_bytes */
|
||||
total_samples_in_input = encoder_session.fmt.iff.data_bytes / encoder_session.info.bytes_per_wide_sample + *options.align_reservoir_samples;
|
||||
|
||||
/* check for chunks trailing the audio data */
|
||||
if(!options.ignore_chunk_sizes && !options.format_options.iff.foreign_metadata
|
||||
&& infilesize != (FLAC__off_t)(-1)) {
|
||||
FLAC__off_t current_position = ftello(encoder_session.fin);
|
||||
if(current_position > 0) {
|
||||
FLAC__uint64 end_of_data_chunk = current_position + encoder_session.fmt.iff.data_bytes;
|
||||
if(end_of_data_chunk < (FLAC__uint64)infilesize) {
|
||||
flac__utils_printf(stderr, 1, "%s: WARNING: there is data trailing the audio data. Use --keep-foreign-metadata or --ignore-chunk-sizes to keep it\n", encoder_session.inbasefilename);
|
||||
if(encoder_session.treat_warnings_as_errors)
|
||||
return EncoderSession_finish_error(&encoder_session);
|
||||
}
|
||||
else if(end_of_data_chunk > (FLAC__uint64)infilesize) {
|
||||
flac__utils_printf(stderr, 1, "%s: WARNING: the length of the data chunk overruns the end of the file. Please consult the manual on the --ignore-chunk-sizes option\n", encoder_session.inbasefilename);
|
||||
if(encoder_session.treat_warnings_as_errors)
|
||||
return EncoderSession_finish_error(&encoder_session);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FORMAT_FLAC:
|
||||
case FORMAT_OGGFLAC:
|
||||
|
@ -1734,7 +1734,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
|
||||
{
|
||||
FILE *encode_infile;
|
||||
FLAC__byte lookahead[12];
|
||||
uint32_t lookahead_length = 0;
|
||||
uint32_t lookahead_length = 0, master_chunk_size = 0;
|
||||
FileFormat input_format = FORMAT_RAW;
|
||||
int retval;
|
||||
FLAC__off_t infilesize;
|
||||
@ -1830,12 +1830,27 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
|
||||
}
|
||||
}
|
||||
|
||||
if(!option_values.ignore_chunk_sizes && (input_format == FORMAT_WAVE || input_format == FORMAT_AIFF) && infilesize >= UINT32_MAX) {
|
||||
if(!option_values.ignore_chunk_sizes
|
||||
&& (input_format == FORMAT_WAVE || input_format == FORMAT_AIFF || input_format == FORMAT_AIFF_C)
|
||||
&& infilesize >= UINT32_MAX) {
|
||||
conditional_fclose(encode_infile);
|
||||
return usage_error("ERROR: file %s is too large to be valid.\n"
|
||||
"Please consult the manual on the --ignore-chunk-sizes option\n\n", infilename);
|
||||
}
|
||||
|
||||
if(input_format == FORMAT_WAVE || input_format == FORMAT_AIFF || input_format == FORMAT_AIFF_C) {
|
||||
if(input_format == FORMAT_WAVE)
|
||||
master_chunk_size = lookahead[4] + (lookahead[5] << 8) + (lookahead[6] << 16) + (lookahead[7] << 24);
|
||||
else if(input_format == FORMAT_AIFF || input_format == FORMAT_AIFF_C)
|
||||
master_chunk_size = (lookahead[4] << 24) + (lookahead[5] << 16) + (lookahead[6] << 8) + lookahead[7];
|
||||
|
||||
if(infilesize != (FLAC__off_t)(-1) && infilesize > 8 && (infilesize - 8) != master_chunk_size) {
|
||||
flac__utils_printf(stderr, 1, "WARNING: %s chunk size of file %s does not agree with filesize\n", (input_format == FORMAT_WAVE)?"RIFF":"FORM", infilename);
|
||||
if(option_values.treat_warnings_as_errors)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(option_values.keep_foreign_metadata || option_values.keep_foreign_metadata_if_present) {
|
||||
if(encode_infile == stdin || option_values.force_to_stdout) {
|
||||
conditional_fclose(encode_infile);
|
||||
|
Loading…
x
Reference in New Issue
Block a user