# HG changeset patch # User nicodvb # Date 1153067645 0 # Node ID 017a563d8d93431ad73da2c52a66d86af25fc539 # Parent 056e102f7c0ea077a80fcafcde68aca62b8ca4c3 prevent buffer underflow; the code is still incorrect and leads to desync but at least it doesn't crash diff -r 056e102f7c0e -r 017a563d8d93 libmpcodecs/ad_hwmpa.c --- a/libmpcodecs/ad_hwmpa.c Sun Jul 16 15:54:27 2006 +0000 +++ b/libmpcodecs/ad_hwmpa.c Sun Jul 16 16:34:05 2006 +0000 @@ -14,7 +14,6 @@ #include "libmpdemux/mp3_hdr.h" //based on ad_hwac3.c and ad_libmad.c -static int isdts = -1; static ad_info_t info = { @@ -84,23 +83,33 @@ static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen) { - int len, start, cnt2, tot; + int len, start, tot; int chans, srate, spf, mpa_layer, br; - tot = cnt2 = 0; - while(tot < minlen && tot+4608<=maxlen) + tot = 0; + + while(tot < minlen) { start = mpa_sync(sh, 1, &len, &chans, &srate, &spf, &mpa_layer, &br); - if(start < 0) + if(start < 0 || tot + len > maxlen) break; - if(start + len < sh->a_in_buffer_len && start + len >= maxlen) - break; - memcpy(&buf[cnt2], &(sh->a_in_buffer[start]), len); - cnt2 += len; + if(start + len > sh->a_in_buffer_len) + { + int l; + l = min(sh->a_in_buffer_size - sh->a_in_buffer_len, start + len); + l = demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len], l); + if(! l) + return tot; + sh->a_in_buffer_len += l; + continue; + } + + memcpy(&buf[tot], &(sh->a_in_buffer[start]), len); + tot += len; + sh->a_in_buffer_len -= start + len; memmove(sh->a_in_buffer, &(sh->a_in_buffer[start + len]), sh->a_in_buffer_len); - tot += start + len; } return tot;