From 72f3e3555b2a757e4b41eea0dd828dbdb04df037 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 9 Jan 2017 09:24:44 -0800 Subject: [PATCH] Added sanity check to MCA decoder, fixes some odd rips I've just encountered. --- src/meta/mca.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/meta/mca.c b/src/meta/mca.c index 518dd16b..42ec643c 100644 --- a/src/meta/mca.c +++ b/src/meta/mca.c @@ -11,7 +11,7 @@ VGMSTREAM * init_vgmstream_mca(STREAMFILE *streamFile) { int channel_count; int loop_flag; int version; - size_t head_size, data_size; + size_t head_size, data_size, file_size; off_t start_offset, coef_offset, coef_start, coef_shift; int i, j; int coef_spacing; @@ -78,6 +78,16 @@ VGMSTREAM * init_vgmstream_mca(STREAMFILE *streamFile) { coef_offset = coef_start + coef_shift * 0x14; } + /* sanity check */ + file_size = get_streamfile_size(streamFile); + + if (start_offset + data_size > file_size) { + if (head_size + data_size > file_size) + goto fail; + + start_offset = file_size - data_size; + } + /* set up ADPCM coefs */ for (j = 0; jchannels; j++) {