From 74001e74bafd3654e178e65d9e277158da5bc728 Mon Sep 17 00:00:00 2001 From: NicknineTheEagle Date: Sun, 1 Dec 2019 23:15:08 +0300 Subject: [PATCH] VAG: Added extra checks --- src/meta/vag.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/meta/vag.c b/src/meta/vag.c index cbb2cc16..e231679b 100644 --- a/src/meta/vag.c +++ b/src/meta/vag.c @@ -199,13 +199,15 @@ VGMSTREAM * init_vgmstream_vag(STREAMFILE *streamFile) { interleave = 0x800; loop_flag = 0; } - else if (read_32bitBE(0x24, streamFile) == 0x56414778) { /* VAGx" */ + else if (read_32bitBE(0x24, streamFile) == 0x56414778) { /* "VAGx" */ /* Need for Speed: Hot Pursuit 2 (PS2) */ start_offset = 0x30; channel_count = read_32bitBE(0x2c, streamFile); channel_size = channel_size / channel_count; loop_flag = 0; + if (file_size % 0x10 != 0) goto fail; + /* detect interleave using end markers */ interleave = 0; @@ -214,7 +216,7 @@ VGMSTREAM * init_vgmstream_vag(STREAMFILE *streamFile) { off_t end_off = 0; uint8_t flag; - while (1) { + while (offset > start_offset) { offset -= 0x10; flag = read_8bit(offset + 0x01, streamFile); if (flag == 0x01) { @@ -225,9 +227,9 @@ VGMSTREAM * init_vgmstream_vag(STREAMFILE *streamFile) { break; } } - - if (offset == start_offset) goto fail; } + + if (!interleave) goto fail; } } else {