From bdfa962b2a5ea20b934dbe030b7fe23832f6ee7c Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Wed, 13 Jan 2010 18:43:59 +0100 Subject: arithmetic exception fix in mpgmad plugin --- plugins/mpgmad/mpgmad.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'plugins') diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c index 0dec44d0..55bced8f 100644 --- a/plugins/mpgmad/mpgmad.c +++ b/plugins/mpgmad/mpgmad.c @@ -28,6 +28,9 @@ #define min(x,y) ((x)<(y)?(x):(y)) #define max(x,y) ((x)>(y)?(x):(y)) +#define likely(x) __builtin_expect((x),1) +#define unlikely(x) __builtin_expect((x),0) + static DB_decoder_t plugin; static DB_functions_t *deadbeef; @@ -659,6 +662,10 @@ MadFixedToFloat (mad_fixed_t Fixed) { static int cmp3_decode_cut (int framesize) { if (buffer.duration >= 0) { + if (unlikely (!buffer.channels || buffer.channels > 2)) { + trace ("mpgmad: got frame with invalid number of channels (%d)\n", buffer.channels); + return 1; + } if (buffer.currentsample + buffer.readsize / (framesize * buffer.channels) > buffer.endsample) { int sz = (buffer.endsample - buffer.currentsample + 1) * framesize * buffer.channels; trace ("size truncated to %d bytes, cursample=%d, endsample=%d, totalsamples=%d\n", buffer.readsize, buffer.currentsample, buffer.endsample, buffer.totalsamples); -- cgit v1.2.3