comparison minijss/jloadxm.c @ 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
comparison
equal deleted inserted replaced
1160:b122ad2d3fbe 1161:92cee852a8af
19 #define XM_MaxInstruments (128) 19 #define XM_MaxInstruments (128)
20 #define XM_MaxInstSamples (16) 20 #define XM_MaxInstSamples (16)
21 #define XM_MaxEnvPoints (12) 21 #define XM_MaxEnvPoints (12)
22 #define XM_MaxNotes (96) 22 #define XM_MaxNotes (96)
23 #define XM_MaxSampleVolume (64) 23 #define XM_MaxSampleVolume (64)
24 24 #define XM_HeaderSize 276
25 25
26 /* XM format structures 26 /* XM format structures
27 */ 27 */
28 typedef struct 28 typedef struct
29 { 29 {
809 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, 809 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
810 "Number of instruments was invalid, %d (should be 1 - %d).\n", 810 "Number of instruments was invalid, %d (should be 1 - %d).\n",
811 xmH.ninstruments, XM_MaxInstruments); 811 xmH.ninstruments, XM_MaxInstruments);
812 } 812 }
813 813
814 if (xmH.headSize < XM_HeaderSize)
815 {
816 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
817 "XM header size less than %d bytes (%d bytes).\n",
818 XM_HeaderSize, xmH.headSize);
819 }
820
814 switch (xmH.version) 821 switch (xmH.version)
815 { 822 {
816 case 0x0104: 823 case 0x0104:
817 break; 824 break;
818 825
824 831
825 if (!dmf_read_str(inFile, &xmH.orderList, sizeof(xmH.orderList))) 832 if (!dmf_read_str(inFile, &xmH.orderList, sizeof(xmH.orderList)))
826 { 833 {
827 JSSERROR(DMERR_FREAD, DMERR_FREAD, 834 JSSERROR(DMERR_FREAD, DMERR_FREAD,
828 "Error reading pattern order list.\n"); 835 "Error reading pattern order list.\n");
836 }
837
838 if (xmH.headSize > 276)
839 {
840 JSSWARNING(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
841 "XM header size > %d bytes, skipping the rest.\n",
842 XM_HeaderSize, xmH.headSize);
843 dmfseek(inFile, xmH.headSize - XM_HeaderSize, SEEK_CUR);
829 } 844 }
830 845
831 /* Okay, allocate a module structure 846 /* Okay, allocate a module structure
832 */ 847 */
833 module = jssAllocateModule(); 848 module = jssAllocateModule();