# HG changeset patch # User Matti Hamalainen # Date 1509375455 -7200 # Node ID 496d04ab495fccf8bde68d4e54ffb46a25b5e041 # Parent 30c888dfec9ff509b27c329240f88149fd06daf3 Improve error checking and resiliency a bit. diff -r 30c888dfec9f -r 496d04ab495f minijss/jloadxm.c --- 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); }