diff --git a/src/libFLAC/ogg_decoder_aspect.c b/src/libFLAC/ogg_decoder_aspect.c index 8e8b65635b..3f18e10222 100644 --- a/src/libFLAC/ogg_decoder_aspect.c +++ b/src/libFLAC/ogg_decoder_aspect.c @@ -146,15 +146,15 @@ static FLAC__OggDecoderAspectReadStatus process_page_(FLAC__OggDecoderAspect *as static FLAC__bool check_size_of_link_allocation_(FLAC__OggDecoderAspect *aspect) { - /* reallocate in chunks of 4 */ + /* double on reallocating */ if(aspect->current_linknumber >= aspect->number_of_links_allocated || aspect->current_linknumber_advance_read >= aspect->number_of_links_allocated) { FLAC__OggDecoderAspect_LinkDetails * tmpptr = NULL; - if(NULL == (tmpptr = safe_realloc_nofree_mul_2op_(aspect->linkdetails,4+aspect->number_of_links_allocated,sizeof(FLAC__OggDecoderAspect_LinkDetails)))) { + if(NULL == (tmpptr = safe_realloc_nofree_mul_2op_(aspect->linkdetails,2*aspect->number_of_links_allocated,sizeof(FLAC__OggDecoderAspect_LinkDetails)))) { return false; } aspect->linkdetails = tmpptr; - memset(aspect->linkdetails + aspect->number_of_links_allocated, 0, 4 * sizeof(FLAC__OggDecoderAspect_LinkDetails)); - aspect->number_of_links_allocated += 4; + memset(aspect->linkdetails + aspect->number_of_links_allocated, 0, aspect->number_of_links_allocated * sizeof(FLAC__OggDecoderAspect_LinkDetails)); + aspect->number_of_links_allocated *= 2; } return true; } @@ -454,6 +454,11 @@ FLAC__OggDecoderAspectReadStatus FLAC__ogg_decoder_aspect_skip_link(FLAC__OggDec if(seek_callback == NULL || tell_callback == NULL || length_callback == NULL) return FLAC__OGG_DECODER_ASPECT_READ_STATUS_CALLBACKS_NONFUNCTIONAL; + /* This extra check is here, because allocation failures while reading cannot always be + * properly passed down the chain with the current API. So, instead, check again */ + if(!check_size_of_link_allocation_(aspect)) + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR; + if(aspect->current_linknumber < aspect->number_of_links_indexed) { if(aspect->linkdetails[aspect->current_linknumber].is_last) { /* Seek to end of stream */