changeset 1400:496d04ab495f

Improve error checking and resiliency a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 30 Oct 2017 16:57:35 +0200
parents 30c888dfec9f
children aaed8fa9a11f
files minijss/jloadxm.c
diffstat 1 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/minijss/jloadxm.c	Mon Oct 30 05:38:37 2017 +0200
+++ b/minijss/jloadxm.c	Mon Oct 30 16:57:35 2017 +0200
@@ -530,13 +530,20 @@
         !dmf_read_str(inFile, &xmS.sampleName, sizeof(xmS.sampleName)))
     {
         JSSERROR(DMERR_FREAD, DMERR_FREAD,
-            "Error reading instrument sample header #%d/%d [%d]",
+            "Error reading instrument sample header #%d/%d [%d]\n",
             neinst, nsample, module->ninstruments);
     }
 
     if (xmS.size <= 0)
         return DMERR_OK;
 
+    if (xmS.size > 16 * 1024 * 1024)
+    {
+        JSSERROR(DMERR_FREAD, DMERR_FREAD,
+            "Sample instrument #%d/%d [%d] too large, %d bytes.\n",
+            neinst, nsample, module->ninstruments, xmS.size);
+    }
+
     // Allocate sample instrument
     JSSDEBUG("Allocating sample #%d/%d [%d]\n",
         neinst, nsample, module->ninstruments);
@@ -951,11 +958,9 @@
     if (xmH.norders > XM_MaxOrders)
     {
         if (!probe)
-            JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
+            JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
                 "Number of orders %d > %d, possibly broken module.\n",
                 xmH.norders, XM_MaxOrders);
-
-        xmH.norders = XM_MaxOrders;
     }
 
     if (xmH.norders == 0)
@@ -968,24 +973,22 @@
     if (xmH.npatterns > XM_MaxPatterns)
     {
         if (!probe)
-            JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
+            JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
                 "Number of patterns %d > %d, possibly broken module.\n",
                 xmH.npatterns, XM_MaxPatterns);
-
-        xmH.npatterns = XM_MaxPatterns;
     }
 
     if (xmH.npatterns == 0)
     {
         if (!probe)
-            JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
+            JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
                 "Number of patterns was zero.\n");
     }
 
     if (xmH.nchannels <= 0 || xmH.nchannels > XM_MaxChannels)
     {
         if (!probe)
-            JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
+            JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
                 "Number of channels was invalid, %d (should be 1 - %d).\n",
                 xmH.nchannels, XM_MaxChannels);
     }
@@ -993,7 +996,7 @@
     if (xmH.ninstruments <= 0 || xmH.ninstruments > XM_MaxInstruments)
     {
         if (!probe)
-            JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
+            JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
                 "Number of instruments was invalid, %d (should be 1 - %d).\n",
                 xmH.ninstruments, XM_MaxInstruments);
     }