From 6bbfbb5e1da6de7d29861e52c601b343ef724520 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Tue, 27 Jun 2017 01:50:59 +0000 Subject: [PATCH] Fix crash when attempting to play an IVF video in 8-bit. git-svn-id: https://svn.eduke32.com/eduke32@6290 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/anim.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/duke3d/src/anim.cpp b/source/duke3d/src/anim.cpp index 10fc7db3d..84c588da1 100644 --- a/source/duke3d/src/anim.cpp +++ b/source/duke3d/src/anim.cpp @@ -395,7 +395,7 @@ int32_t Anim_Play(const char *fn) int32_t length = kfilelength(handle); - if (length == 0) + if (length <= 4) { OSD_Printf("Warning: skipping playback of empty ANM file \"%s\".\n", fn); goto end_anim; @@ -413,9 +413,19 @@ int32_t Anim_Play(const char *fn) kread(handle, anim->animbuf, length); kclose(handle); + uint32_t firstfour; + Bmemcpy(&firstfour, anim->animbuf, 4); + + // "DKIF" (.ivf) + if (firstfour == B_LITTLE32(0x46494B44)) + goto end_anim; + int32_t numframes; - if (ANIM_LoadAnim(anim->animbuf, length) < 0 || (numframes = ANIM_NumFrames()) <= 0) + // "LPF " (.anm) + if (firstfour != B_LITTLE32(0x2046504C) || + ANIM_LoadAnim(anim->animbuf, length) < 0 || + (numframes = ANIM_NumFrames()) <= 0) { // XXX: ANM_LoadAnim() still checks less than the bare minimum, // e.g. ANM file could still be too small and not contain any frames.