Allow mono MSADPCM; validate interleave for endless loops in some codecs

This commit is contained in:
bnnm 2017-04-29 20:28:14 +02:00
parent af2b5d4e76
commit cac3af887a

View File

@ -165,11 +165,11 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
{ {
if (coding == coding_SDX2) { if (coding == coding_SDX2) {
coding = coding_SDX2_int; coding = coding_SDX2_int;
vgmstream->coding_type = coding_SDX2_int;
} }
//todo if 0 do this too (most codecs seem to enter an infinite loop otherwise)
if(vgmstream->interleave_block_size==0xffffffff) if (vgmstream->interleave_block_size==0xffffffff) {
vgmstream->layout_type = layout_none; vgmstream->layout_type = layout_none;
}
else { else {
vgmstream->layout_type = layout_interleave; vgmstream->layout_type = layout_interleave;
if (coding == coding_DVI_IMA) if (coding == coding_DVI_IMA)
@ -177,6 +177,16 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
if (coding == coding_IMA) if (coding == coding_IMA)
coding = coding_IMA_int; coding = coding_IMA_int;
} }
/* to avoid endless loops */
if (!interleave && (
coding == coding_PSX ||
coding == coding_PSX_badflags ||
coding == coding_IMA_int ||
coding == coding_DVI_IMA_int ||
coding == coding_SDX2_int) ) {
goto fail;
}
} else { } else {
vgmstream->layout_type = layout_none; vgmstream->layout_type = layout_none;
} }
@ -191,11 +201,15 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
break; break;
case coding_MS_IMA: case coding_MS_IMA:
if (!interleave) goto fail; /* creates garbage */
vgmstream->interleave_block_size = interleave; vgmstream->interleave_block_size = interleave;
vgmstream->layout_type = layout_none; vgmstream->layout_type = layout_none;
break; break;
case coding_MSADPCM: case coding_MSADPCM:
if (channel_count != 2) goto fail; if (channel_count > 2) goto fail;
if (!interleave) goto fail; /* creates garbage */
vgmstream->interleave_block_size = interleave; vgmstream->interleave_block_size = interleave;
vgmstream->layout_type = layout_none; vgmstream->layout_type = layout_none;
break; break;
@ -208,9 +222,11 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
break; break;
case coding_NGC_DSP: case coding_NGC_DSP:
if (dsp_interleave_type == 0) { if (dsp_interleave_type == 0) {
if (!interleave) goto fail;
vgmstream->layout_type = layout_interleave; vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = interleave; vgmstream->interleave_block_size = interleave;
} else if (dsp_interleave_type == 1) { } else if (dsp_interleave_type == 1) {
if (!interleave) goto fail;
vgmstream->layout_type = layout_interleave_byte; vgmstream->layout_type = layout_interleave_byte;
vgmstream->interleave_block_size = interleave; vgmstream->interleave_block_size = interleave;
} else if (dsp_interleave_type == 2) { } else if (dsp_interleave_type == 2) {