changeset 1161:92cee852a8af

Check header size against the known values. Bail out if it's too small, and skip unknown data if header specifies larger value than what we read.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 07:01:42 +0200
parents b122ad2d3fbe
children 409926df7bea
files minijss/jloadxm.c
diffstat 1 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/minijss/jloadxm.c	Thu Mar 05 07:00:58 2015 +0200
+++ b/minijss/jloadxm.c	Thu Mar 05 07:01:42 2015 +0200
@@ -21,7 +21,7 @@
 #define XM_MaxEnvPoints     (12)
 #define XM_MaxNotes         (96)
 #define XM_MaxSampleVolume  (64)
-
+#define XM_HeaderSize       276
 
 /* XM format structures
  */
@@ -811,6 +811,13 @@
         xmH.ninstruments, XM_MaxInstruments);
     }
 
+    if (xmH.headSize < XM_HeaderSize)
+    {
+        JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
+        "XM header size less than %d bytes (%d bytes).\n",
+        XM_HeaderSize, xmH.headSize);
+    }
+
     switch (xmH.version)
     {
         case 0x0104:
@@ -828,6 +835,14 @@
         "Error reading pattern order list.\n");
     }
 
+    if (xmH.headSize > 276)
+    {
+        JSSWARNING(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
+        "XM header size > %d bytes, skipping the rest.\n",
+        XM_HeaderSize, xmH.headSize);
+        dmfseek(inFile, xmH.headSize - XM_HeaderSize, SEEK_CUR);
+    }
+
     /* Okay, allocate a module structure
      */
     module = jssAllocateModule();