Check first metadata block is streaminfo in level 1 metadata iterator

In simple_iterator_prime_input_ there was no check whether the first
metadata block is a streaminfo block. As the rest of the functions
operate under the assumption the first block is a streaminfo block,
for example to prevent the functions from deleting the last block
and being left with an iterator pointing nowhere, this check is
added.
This commit is contained in:
Martijn van Beurden 2022-06-18 16:23:30 +02:00
parent b963ce0873
commit 772efde6a7

View File

@ -446,7 +446,15 @@ static FLAC__bool simple_iterator_prime_input_(FLAC__Metadata_SimpleIterator *it
case 0:
iterator->depth = 0;
iterator->first_offset = iterator->offset[iterator->depth] = ftello(iterator->file);
return read_metadata_block_header_(iterator);
ret = read_metadata_block_header_(iterator);
/* The first metadata block must be a streaminfo. If this is not the
* case, the file is invalid and assumptions made elsewhere in the
* code are invalid */
if(iterator->type != FLAC__METADATA_TYPE_STREAMINFO) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA;
return false;
}
return ret;
case 1:
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
return false;