gosu 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +108 -14
  3. data/dependencies/SDL/include/SDL_assert.h +81 -50
  4. data/dependencies/SDL/include/SDL_atomic.h +135 -35
  5. data/dependencies/SDL/include/SDL_audio.h +960 -355
  6. data/dependencies/SDL/include/SDL_bits.h +11 -6
  7. data/dependencies/SDL/include/SDL_blendmode.h +91 -14
  8. data/dependencies/SDL/include/SDL_clipboard.h +30 -7
  9. data/dependencies/SDL/include/SDL_config.h +277 -27
  10. data/dependencies/SDL/include/SDL_config_android.h +13 -38
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
  12. data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
  13. data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
  14. data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
  15. data/dependencies/SDL/include/SDL_config_psp.h +16 -37
  16. data/dependencies/SDL/include/SDL_config_windows.h +28 -91
  17. data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
  18. data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
  19. data/dependencies/SDL/include/SDL_copying.h +1 -1
  20. data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
  21. data/dependencies/SDL/include/SDL_egl.h +906 -280
  22. data/dependencies/SDL/include/SDL_endian.h +101 -47
  23. data/dependencies/SDL/include/SDL_error.h +70 -19
  24. data/dependencies/SDL/include/SDL_events.h +387 -79
  25. data/dependencies/SDL/include/SDL_filesystem.h +73 -64
  26. data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
  27. data/dependencies/SDL/include/SDL_gesture.h +36 -6
  28. data/dependencies/SDL/include/SDL_haptic.h +304 -210
  29. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1286 -897
  31. data/dependencies/SDL/include/SDL_joystick.h +577 -130
  32. data/dependencies/SDL/include/SDL_keyboard.h +162 -63
  33. data/dependencies/SDL/include/SDL_keycode.h +7 -5
  34. data/dependencies/SDL/include/SDL_loadso.h +42 -8
  35. data/dependencies/SDL/include/SDL_locale.h +34 -32
  36. data/dependencies/SDL/include/SDL_log.h +212 -19
  37. data/dependencies/SDL/include/SDL_main.h +72 -17
  38. data/dependencies/SDL/include/SDL_messagebox.h +70 -23
  39. data/dependencies/SDL/include/SDL_metal.h +27 -32
  40. data/dependencies/SDL/include/SDL_misc.h +19 -15
  41. data/dependencies/SDL/include/SDL_mouse.h +262 -110
  42. data/dependencies/SDL/include/SDL_mutex.h +286 -66
  43. data/dependencies/SDL/include/SDL_name.h +1 -1
  44. data/dependencies/SDL/include/SDL_opengl.h +1 -1
  45. data/dependencies/SDL/include/SDL_opengles.h +1 -1
  46. data/dependencies/SDL/include/SDL_opengles2.h +2 -2
  47. data/dependencies/SDL/include/SDL_pixels.h +199 -34
  48. data/dependencies/SDL/include/SDL_platform.h +39 -2
  49. data/dependencies/SDL/include/SDL_power.h +23 -10
  50. data/dependencies/SDL/include/SDL_quit.h +1 -1
  51. data/dependencies/SDL/include/SDL_rect.h +78 -28
  52. data/dependencies/SDL/include/SDL_render.h +1204 -472
  53. data/dependencies/SDL/include/SDL_revision.h +2 -2
  54. data/dependencies/SDL/include/SDL_rwops.h +605 -33
  55. data/dependencies/SDL/include/SDL_scancode.h +1 -1
  56. data/dependencies/SDL/include/SDL_sensor.h +76 -42
  57. data/dependencies/SDL/include/SDL_shape.h +38 -27
  58. data/dependencies/SDL/include/SDL_stdinc.h +96 -24
  59. data/dependencies/SDL/include/SDL_surface.h +571 -139
  60. data/dependencies/SDL/include/SDL_system.h +339 -101
  61. data/dependencies/SDL/include/SDL_syswm.h +50 -20
  62. data/dependencies/SDL/include/SDL_test.h +1 -1
  63. data/dependencies/SDL/include/SDL_test_assert.h +2 -2
  64. data/dependencies/SDL/include/SDL_test_common.h +23 -6
  65. data/dependencies/SDL/include/SDL_test_compare.h +1 -1
  66. data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
  67. data/dependencies/SDL/include/SDL_test_font.h +3 -3
  68. data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
  69. data/dependencies/SDL/include/SDL_test_harness.h +6 -6
  70. data/dependencies/SDL/include/SDL_test_images.h +1 -1
  71. data/dependencies/SDL/include/SDL_test_log.h +1 -1
  72. data/dependencies/SDL/include/SDL_test_md5.h +1 -1
  73. data/dependencies/SDL/include/SDL_test_memory.h +1 -1
  74. data/dependencies/SDL/include/SDL_test_random.h +2 -2
  75. data/dependencies/SDL/include/SDL_thread.h +226 -128
  76. data/dependencies/SDL/include/SDL_timer.h +129 -22
  77. data/dependencies/SDL/include/SDL_touch.h +48 -8
  78. data/dependencies/SDL/include/SDL_types.h +1 -1
  79. data/dependencies/SDL/include/SDL_version.h +72 -46
  80. data/dependencies/SDL/include/SDL_video.h +1266 -460
  81. data/dependencies/SDL/include/SDL_vulkan.h +100 -161
  82. data/dependencies/SDL/include/begin_code.h +22 -1
  83. data/dependencies/SDL/include/close_code.h +1 -1
  84. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  85. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  86. data/dependencies/SDL_sound/SDL_sound.c +83 -7
  87. data/dependencies/SDL_sound/SDL_sound.h +4 -4
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
  89. data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
  100. data/dependencies/SDL_sound/dr_flac.h +618 -220
  101. data/dependencies/SDL_sound/dr_mp3.h +263 -94
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
  103. data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
  104. data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
  105. data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
  107. data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
  108. data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
  109. data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
  110. data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
  111. data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
  118. data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
  119. data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
  120. data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
  121. data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
  122. data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
  123. data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
  124. data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
  125. data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
  126. data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
  127. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
  128. data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
  129. data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
  131. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
  132. data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
  133. data/dependencies/SDL_sound/stb_vorbis.h +508 -325
  134. data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
  135. data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
  136. data/dependencies/mojoAL/mojoal.c +4594 -0
  137. data/ext/gosu/extconf.rb +29 -30
  138. data/include/Gosu/Audio.hpp +70 -85
  139. data/include/Gosu/Color.hpp +19 -11
  140. data/include/Gosu/Font.hpp +40 -44
  141. data/include/Gosu/Graphics.hpp +58 -71
  142. data/include/Gosu/GraphicsBase.hpp +26 -33
  143. data/include/Gosu/Image.hpp +56 -62
  144. data/include/Gosu/ImageData.hpp +23 -27
  145. data/include/Gosu/Inspection.hpp +1 -4
  146. data/include/Gosu/TextInput.hpp +34 -40
  147. data/include/Gosu/Version.hpp +1 -1
  148. data/include/Gosu/Window.hpp +71 -70
  149. data/lib/SDL2.dll +0 -0
  150. data/lib/gosu/compat.rb +24 -37
  151. data/lib/gosu.rb +2 -2
  152. data/lib64/SDL2.dll +0 -0
  153. data/src/Audio.cpp +86 -86
  154. data/src/AudioFile.hpp +6 -6
  155. data/src/AudioFileAudioToolbox.cpp +1 -1
  156. data/src/AudioFileSDLSound.cpp +1 -1
  157. data/src/AudioImpl.hpp +5 -5
  158. data/src/BitmapIO.cpp +0 -20
  159. data/src/BlockAllocator.cpp +2 -1
  160. data/src/Channel.cpp +22 -20
  161. data/src/Color.cpp +12 -9
  162. data/src/EmptyImageData.hpp +15 -17
  163. data/src/FileUnix.cpp +1 -1
  164. data/src/FileWin.cpp +1 -1
  165. data/src/Font.cpp +48 -53
  166. data/src/Graphics.cpp +135 -143
  167. data/src/Image.cpp +41 -42
  168. data/src/Input.cpp +1 -1
  169. data/src/InputUIKit.cpp +1 -1
  170. data/src/LargeImageData.cpp +108 -101
  171. data/src/LargeImageData.hpp +17 -15
  172. data/src/Log.hpp +6 -6
  173. data/src/Macro.cpp +35 -37
  174. data/src/Macro.hpp +11 -11
  175. data/src/Math.cpp +8 -1
  176. data/src/Resolution.cpp +12 -7
  177. data/src/RubyGosu.cxx +5 -5
  178. data/src/TexChunk.cpp +50 -41
  179. data/src/TexChunk.hpp +22 -22
  180. data/src/Text.cpp +37 -37
  181. data/src/TextBuilder.cpp +60 -57
  182. data/src/TextBuilder.hpp +20 -20
  183. data/src/TextInput.cpp +127 -135
  184. data/src/TrueTypeFont.cpp +107 -107
  185. data/src/TrueTypeFont.hpp +39 -38
  186. data/src/TrueTypeFontApple.cpp +19 -22
  187. data/src/TrueTypeFontUnix.cpp +21 -26
  188. data/src/TrueTypeFontWin.cpp +30 -30
  189. data/src/Window.cpp +95 -86
  190. data/src/WindowUIKit.cpp +46 -49
  191. metadata +7 -17
  192. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  193. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  194. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  195. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  196. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  197. data/dependencies/al_soft/AL/alext.h +0 -585
  198. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  199. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  200. data/dependencies/al_soft/AL/efx.h +0 -762
  201. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  202. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  203. data/lib/OpenAL32.dll +0 -0
  204. data/lib64/OpenAL32.dll +0 -0
@@ -6,7 +6,6 @@
6
6
  */
7
7
 
8
8
  #include "libmodplug.h"
9
- #include "tables.h"
10
9
 
11
10
  //////////////////////////////////////////////////////////
12
11
  // ProTracker / NoiseTracker MOD/NST file support
@@ -34,7 +33,9 @@ void CSoundFile_ConvertModCommand(CSoundFile *_this, MODCOMMAND *m)
34
33
  case 0x0D: command = CMD_PATTERNBREAK; param = ((param >> 4) * 10) + (param & 0x0F); break;
35
34
  case 0x0E: command = CMD_MODCMDEX; break;
36
35
  case 0x0F: command = (param <= (UINT)((_this->m_nType & (MOD_TYPE_XM|MOD_TYPE_MT2)) ? 0x1F : 0x20)) ? CMD_SPEED : CMD_TEMPO;
37
- if ((param == 0xFF) && (_this->m_nSamples == 15)) command = 0; break;
36
+ if((param == 0xFF) && (_this->m_nSamples == 15))
37
+ command = 0;
38
+ break;
38
39
  // Extension for XM extended effects
39
40
  case 'G' - 55: command = CMD_GLOBALVOLUME; break;
40
41
  case 'H' - 55: command = CMD_GLOBALVOLSLIDE; if (param & 0xF0) param &= 0xF0; break;
@@ -54,9 +55,7 @@ void CSoundFile_ConvertModCommand(CSoundFile *_this, MODCOMMAND *m)
54
55
  m->param = param;
55
56
  }
56
57
 
57
-
58
58
  #pragma pack(1)
59
-
60
59
  typedef struct _MODSAMPLE
61
60
  {
62
61
  CHAR name[22];
@@ -74,19 +73,33 @@ typedef struct _MODMAGIC
74
73
  BYTE Orders[128];
75
74
  char Magic[4]; // changed from CHAR
76
75
  } MODMAGIC, *PMODMAGIC;
77
-
78
76
  #pragma pack()
79
77
 
78
+ static BOOL IsValidName(LPCSTR s, int length, CHAR minChar)
79
+ //-----------------------------------------------------------------
80
+ {
81
+ int i, nt;
82
+ for (i = 0, nt = 0; i < length; i++)
83
+ {
84
+ if(s[i])
85
+ {
86
+ if (nt) return FALSE;// garbage after null
87
+ if (s[i] < minChar) return FALSE;// caller says it's garbage
88
+ }
89
+ else if (!nt) nt = i;// found null terminator
90
+ }
91
+ return TRUE;
92
+ }
93
+
80
94
  static BOOL IsMagic(LPCSTR s1, LPCSTR s2)
81
95
  {
82
96
  return ((*(DWORD *)s1) == (*(DWORD *)s2)) ? TRUE : FALSE;
83
97
  }
84
98
 
85
-
86
99
  BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLength)
87
100
  //---------------------------------------------------------------
88
101
  {
89
- char s[1024]; // changed from CHAR
102
+ char s[1024]; // changed from CHAR
90
103
  DWORD dwMemPos, dwTotalSampleLen;
91
104
  PMODMAGIC pMagic;
92
105
  UINT nErr;
@@ -101,6 +114,7 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
101
114
  if ((IsMagic(s, "M.K.")) || (IsMagic(s, "M!K!"))
102
115
  || (IsMagic(s, "M&K!")) || (IsMagic(s, "N.T."))) _this->m_nChannels = 4; else
103
116
  if ((IsMagic(s, "CD81")) || (IsMagic(s, "OKTA"))) _this->m_nChannels = 8; else
117
+ if (IsMagic(s, "CD61")) _this->m_nChannels = 6; else
104
118
  if ((s[0]=='F') && (s[1]=='L') && (s[2]=='T') && (s[3]>='4') && (s[3]<='9')) _this->m_nChannels = s[3] - '0'; else
105
119
  if ((s[0]>='2') && (s[0]<='9') && (s[1]=='C') && (s[2]=='H') && (s[3]=='N')) _this->m_nChannels = s[0] - '0'; else
106
120
  if ((s[0]=='1') && (s[1]>='0') && (s[1]<='9') && (s[2]=='C') && (s[3]=='H')) _this->m_nChannels = s[1] - '0' + 10; else
@@ -108,7 +122,12 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
108
122
  if ((s[0]=='3') && (s[1]>='0') && (s[1]<='2') && (s[2]=='C') && (s[3]=='H')) _this->m_nChannels = s[1] - '0' + 30; else
109
123
  if ((s[0]=='T') && (s[1]=='D') && (s[2]=='Z') && (s[3]>='4') && (s[3]<='9')) _this->m_nChannels = s[3] - '0'; else
110
124
  if (IsMagic(s,"16CN")) _this->m_nChannels = 16; else
111
- if (IsMagic(s,"32CN")) _this->m_nChannels = 32; else _this->m_nSamples = 15;
125
+ if (IsMagic(s,"32CN")) _this->m_nChannels = 32;
126
+ else {
127
+ if (!IsValidName((LPCSTR)lpStream, 20, ' '))
128
+ return FALSE;
129
+ _this->m_nSamples = 15;
130
+ }
112
131
  // Load Samples
113
132
  nErr = 0;
114
133
  dwTotalSampleLen = 0;
@@ -118,6 +137,14 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
118
137
  MODINSTRUMENT *psmp = &_this->Ins[i];
119
138
  UINT loopstart, looplen;
120
139
 
140
+ if (_this->m_nSamples == 15)
141
+ {
142
+ if (!IsValidName((LPCSTR)pms->name, 22, 14)) return FALSE;
143
+ if (pms->finetune>>4) return FALSE;
144
+ if (pms->volume > 64) return FALSE;
145
+ if (bswapBE16(pms->length) > 32768) return FALSE;
146
+ }
147
+
121
148
  psmp->uFlags = 0;
122
149
  psmp->nLength = bswapBE16(pms->length)*2;
123
150
  dwTotalSampleLen += psmp->nLength;
@@ -158,7 +185,10 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
158
185
  if ((_this->m_nSamples == 15) && (dwTotalSampleLen > dwMemLength * 4)) return FALSE;
159
186
  pMagic = (PMODMAGIC)(lpStream+dwMemPos);
160
187
  dwMemPos += sizeof(MODMAGIC);
161
- if (_this->m_nSamples == 15) dwMemPos -= 4;
188
+ if (_this->m_nSamples == 15) {
189
+ dwMemPos -= 4;
190
+ if (pMagic->nOrders > 128) return FALSE;
191
+ }
162
192
  SDL_memset(_this->Order, 0,sizeof(_this->Order));
163
193
  SDL_memcpy(_this->Order, pMagic->Orders, 128);
164
194
 
@@ -247,7 +277,7 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
247
277
  LPSTR p = (LPSTR)(lpStream+dwMemPos);
248
278
  UINT flags = 0;
249
279
  if (dwMemPos + 5 >= dwMemLength) break;
250
- if (!SDL_strncasecmp(p, "ADPCM", 5))
280
+ if (!SDL_strncmp(p, "ADPCM", 5))
251
281
  {
252
282
  flags = 3;
253
283
  p += 5;
@@ -260,10 +290,5 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
260
290
  dwErrCheck++;
261
291
  }
262
292
  }
263
- #ifdef MODPLUG_TRACKER
264
- return TRUE;
265
- #else
266
293
  return (dwErrCheck) ? TRUE : FALSE;
267
- #endif
268
294
  }
269
-
@@ -1,3 +1,4 @@
1
+
1
2
  #include "libmodplug.h"
2
3
 
3
4
  #pragma pack(1)
@@ -55,6 +56,7 @@ typedef struct _MT2AUTOMATION
55
56
 
56
57
  typedef struct _MT2INSTRUMENT
57
58
  {
59
+ CHAR szName[32];
58
60
  DWORD dwDataLen;
59
61
  WORD wSamples;
60
62
  BYTE GroupsMapping[96];
@@ -93,6 +95,7 @@ typedef struct _MT2SYNTH
93
95
 
94
96
  typedef struct _MT2SAMPLE
95
97
  {
98
+ CHAR szName[32];
96
99
  DWORD dwDataLen;
97
100
  DWORD dwLength;
98
101
  DWORD dwFrequency;
@@ -204,6 +207,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
204
207
  _this->Order[iOrd] = (BYTE)((iOrd < pfh->nOrders) ? pfh->Orders[iOrd] : 0xFF);
205
208
  }
206
209
  dwMemPos = sizeof(MT2FILEHEADER);
210
+ if (dwMemPos+2 > dwMemLength) return TRUE;
207
211
  nDrumDataLen = *(WORD *)(lpStream + dwMemPos);
208
212
  dwDrumDataPos = dwMemPos + 2;
209
213
  if (nDrumDataLen >= 2) pdd = (MT2DRUMSDATA *)(lpStream+dwDrumDataPos);
@@ -220,7 +224,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
220
224
  DWORD dwId = *(DWORD *)(lpStream+dwMemPos);
221
225
  DWORD dwLen = *(DWORD *)(lpStream+dwMemPos+4);
222
226
  dwMemPos += 8;
223
- if (dwMemPos + dwLen > dwMemLength) return TRUE;
227
+ if (dwLen >= dwMemLength || dwMemPos > dwMemLength - dwLen) return TRUE;
224
228
  switch(dwId)
225
229
  {
226
230
  // MSG
@@ -241,7 +245,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
241
245
  const MT2PATTERN *pmp = (MT2PATTERN *)(lpStream+dwMemPos);
242
246
  UINT wDataLen = (pmp->wDataLen + 1) & ~1;
243
247
  dwMemPos += 6;
244
- if (dwMemPos + wDataLen > dwMemLength) break;
248
+ if (dwMemPos > dwMemLength - wDataLen || wDataLen > dwMemLength) break;
245
249
  UINT nLines = pmp->wLines;
246
250
  if ((iPat < MAX_PATTERNS) && (nLines > 0) && (nLines <= 256))
247
251
  {
@@ -252,7 +256,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
252
256
  UINT len = wDataLen;
253
257
  if (pfh->fulFlags & 1) // Packed Patterns
254
258
  {
255
- BYTE *p = (BYTE *)(lpStream+dwMemPos);
259
+ const BYTE *p = lpStream+dwMemPos;
256
260
  UINT pos = 0, row=0, ch=0;
257
261
  while (pos < len)
258
262
  {
@@ -261,6 +265,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
261
265
  UINT rptcount = 0;
262
266
  if (infobyte == 0xff)
263
267
  {
268
+ if (pos + 2 > len) break;
264
269
  rptcount = p[pos++];
265
270
  infobyte = p[pos++];
266
271
  }
@@ -268,13 +273,13 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
268
273
  {
269
274
  UINT patpos = row*_this->m_nChannels+ch;
270
275
  cmd.note = cmd.instr = cmd.vol = cmd.pan = cmd.fxcmd = cmd.fxparam1 = cmd.fxparam2 = 0;
271
- if (infobyte & 1) cmd.note = p[pos++];
272
- if (infobyte & 2) cmd.instr = p[pos++];
273
- if (infobyte & 4) cmd.vol = p[pos++];
274
- if (infobyte & 8) cmd.pan = p[pos++];
275
- if (infobyte & 16) cmd.fxcmd = p[pos++];
276
- if (infobyte & 32) cmd.fxparam1 = p[pos++];
277
- if (infobyte & 64) cmd.fxparam2 = p[pos++];
276
+ if ((infobyte & 1) && (pos < len)) cmd.note = p[pos++];
277
+ if ((infobyte & 2) && (pos < len)) cmd.instr = p[pos++];
278
+ if ((infobyte & 4) && (pos < len)) cmd.vol = p[pos++];
279
+ if ((infobyte & 8) && (pos < len)) cmd.pan = p[pos++];
280
+ if ((infobyte & 16) && (pos < len)) cmd.fxcmd = p[pos++];
281
+ if ((infobyte & 32) && (pos < len)) cmd.fxparam1 = p[pos++];
282
+ if ((infobyte & 64) && (pos < len)) cmd.fxparam2 = p[pos++];
278
283
  ConvertMT2Command(_this, &m[patpos], &cmd);
279
284
  }
280
285
  row += rptcount+1;
@@ -284,11 +289,12 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
284
289
  } else
285
290
  {
286
291
  const MT2COMMAND *p = (MT2COMMAND *)(lpStream+dwMemPos);
292
+ UINT pos = 0;
287
293
  UINT n = 0;
288
- while ((len > sizeof(MT2COMMAND)) && (n < _this->m_nChannels*nLines))
294
+ while ((pos + sizeof(MT2COMMAND) <= len) && (n < _this->m_nChannels*nLines))
289
295
  {
290
296
  ConvertMT2Command(_this, m, p);
291
- len -= sizeof(MT2COMMAND);
297
+ pos += sizeof(MT2COMMAND);
292
298
  n++;
293
299
  p++;
294
300
  m++;
@@ -338,11 +344,10 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
338
344
  INSTRUMENTHEADER *penv = NULL;
339
345
  if (iIns <= _this->m_nInstruments)
340
346
  {
341
- penv = (INSTRUMENTHEADER *) SDL_malloc(sizeof (INSTRUMENTHEADER));
347
+ penv = (INSTRUMENTHEADER *) SDL_calloc(1,sizeof(INSTRUMENTHEADER));
342
348
  _this->Headers[iIns] = penv;
343
349
  if (penv)
344
350
  {
345
- SDL_memset(penv, 0, sizeof(INSTRUMENTHEADER));
346
351
  penv->nGlobalVol = 64;
347
352
  penv->nPan = 128;
348
353
  for (UINT i=0; i<NOTE_MAX; i++)
@@ -351,8 +356,10 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
351
356
  }
352
357
  }
353
358
  }
354
- if (((LONG)pmi->dwDataLen > 0) && (dwMemPos <= dwMemLength - 40) && (pmi->dwDataLen <= dwMemLength - (dwMemPos + 40)))
359
+ if (pmi->dwDataLen > dwMemLength - (dwMemPos+36)) return TRUE;
360
+ if (pmi->dwDataLen > 0)
355
361
  {
362
+ if (dwMemPos + sizeof(MT2INSTRUMENT) - 4 > dwMemLength) return TRUE;
356
363
  InstrMap[iIns-1] = pmi;
357
364
  if (penv)
358
365
  {
@@ -365,6 +372,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
365
372
  if (pfh->wVersion <= 0x201)
366
373
  {
367
374
  DWORD dwEnvPos = dwMemPos + sizeof(MT2INSTRUMENT) - 4;
375
+ if (dwEnvPos + 2*sizeof(MT2ENVELOPE) > dwMemLength) return TRUE;
368
376
  pehdr[0] = (MT2ENVELOPE *)(lpStream+dwEnvPos);
369
377
  pehdr[1] = (MT2ENVELOPE *)(lpStream+dwEnvPos+8);
370
378
  pehdr[2] = pehdr[3] = NULL;
@@ -374,10 +382,12 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
374
382
  } else
375
383
  {
376
384
  DWORD dwEnvPos = dwMemPos + sizeof(MT2INSTRUMENT);
385
+ if (dwEnvPos > dwMemLength) return TRUE;
377
386
  for (UINT i=0; i<4; i++)
378
387
  {
379
388
  if (pmi->wEnvFlags1 & (1<<i))
380
389
  {
390
+ if (dwEnvPos + sizeof(MT2ENVELOPE) > dwMemLength) return TRUE;
381
391
  pehdr[i] = (MT2ENVELOPE *)(lpStream+dwEnvPos);
382
392
  pedata[i] = (WORD *)pehdr[i]->EnvData;
383
393
  dwEnvPos += sizeof(MT2ENVELOPE);
@@ -459,6 +469,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
459
469
  {
460
470
  if (dwMemPos+36 > dwMemLength) return TRUE;
461
471
  const MT2SAMPLE *pms = (MT2SAMPLE *)(lpStream+dwMemPos);
472
+ if (pms->dwDataLen > dwMemLength - (dwMemPos+36)) return TRUE;
462
473
  if (pms->dwDataLen > 0)
463
474
  {
464
475
  SampleMap[iSmp-1] = pms;
@@ -466,6 +477,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
466
477
  {
467
478
  MODINSTRUMENT *psmp = &_this->Ins[iSmp];
468
479
  psmp->nGlobalVol = 64;
480
+ if (dwMemPos+sizeof(MT2SAMPLE) > dwMemLength) return TRUE;
469
481
  psmp->nVolume = (pms->wVolume >> 7);
470
482
  psmp->nPan = (pms->nPan == 0x80) ? 128 : (pms->nPan^0x80);
471
483
  psmp->nLength = pms->dwLength;
@@ -488,12 +500,12 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
488
500
  }
489
501
  for (UINT iMap=0; iMap<255; iMap++) if (InstrMap[iMap])
490
502
  {
491
- if (dwMemPos+8 > dwMemLength) return TRUE;
492
503
  const MT2INSTRUMENT *pmi = InstrMap[iMap];
493
504
  INSTRUMENTHEADER *penv = NULL;
494
505
  if (iMap<_this->m_nInstruments) penv = _this->Headers[iMap+1];
495
506
  for (UINT iGrp=0; iGrp<pmi->wSamples; iGrp++)
496
507
  {
508
+ if (dwMemPos+8 > dwMemLength) return TRUE;
497
509
  if (penv)
498
510
  {
499
511
  const MT2GROUP *pmg = (MT2GROUP *)(lpStream+dwMemPos);
@@ -522,7 +534,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
522
534
  MODINSTRUMENT *psmp = &_this->Ins[iData+1];
523
535
  if (!(pms->nFlags & 5))
524
536
  {
525
- if (psmp->nLength > 0)
537
+ if (psmp->nLength > 0 && dwMemPos < dwMemLength)
526
538
  {
527
539
  UINT rsflags;
528
540
 
@@ -40,7 +40,7 @@ BOOL CSoundFile_ReadOKT(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
40
40
  {
41
41
  const OKTFILEHEADER *pfh = (OKTFILEHEADER *)lpStream;
42
42
  DWORD dwMemPos = sizeof(OKTFILEHEADER);
43
- UINT nsamples = 0, npatterns = 0, norders = 0;
43
+ UINT nsamples = 0, norders = 0;//, npatterns = 0
44
44
 
45
45
  if ((!lpStream) || (dwMemLength < 1024)) return FALSE;
46
46
  if ((pfh->okta != 0x41544B4F) || (pfh->song != 0x474E4F53)
@@ -56,11 +56,12 @@ BOOL CSoundFile_ReadOKT(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
56
56
  // Reading samples
57
57
  for (UINT smp=1; smp <= nsamples; smp++)
58
58
  {
59
- if (dwMemPos >= dwMemLength) return TRUE;
59
+ if (dwMemPos + sizeof(OKTSAMPLE) >= dwMemLength) return TRUE;
60
60
  if (smp < MAX_SAMPLES)
61
61
  {
62
62
  OKTSAMPLE *psmp = (OKTSAMPLE *)(lpStream + dwMemPos);
63
63
  MODINSTRUMENT *pins = &_this->Ins[smp];
64
+
64
65
  pins->uFlags = 0;
65
66
  pins->nLength = bswapBE32(psmp->length) & ~1;
66
67
  pins->nLoopStart = bswapBE16(psmp->loopstart);
@@ -73,33 +74,36 @@ BOOL CSoundFile_ReadOKT(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
73
74
  dwMemPos += sizeof(OKTSAMPLE);
74
75
  }
75
76
  // SPEE
76
- if (dwMemPos >= dwMemLength) return TRUE;
77
+ if (dwMemPos + 10 > dwMemLength) return TRUE;
77
78
  if (*((DWORD *)(lpStream + dwMemPos)) == 0x45455053)
78
79
  {
79
80
  _this->m_nDefaultSpeed = lpStream[dwMemPos+9];
80
81
  dwMemPos += bswapBE32(*((DWORD *)(lpStream + dwMemPos + 4))) + 8;
81
82
  }
82
83
  // SLEN
83
- if (dwMemPos >= dwMemLength) return TRUE;
84
+ if (dwMemPos + 10 > dwMemLength) return TRUE;
84
85
  if (*((DWORD *)(lpStream + dwMemPos)) == 0x4E454C53)
85
86
  {
86
- npatterns = lpStream[dwMemPos+9];
87
+ if (dwMemPos + 10 > dwMemLength) return TRUE;
88
+ // npatterns = lpStream[dwMemPos+9];
87
89
  dwMemPos += bswapBE32(*((DWORD *)(lpStream + dwMemPos + 4))) + 8;
88
90
  }
89
91
  // PLEN
90
- if (dwMemPos >= dwMemLength) return TRUE;
92
+ if (dwMemPos + 10 > dwMemLength) return TRUE;
91
93
  if (*((DWORD *)(lpStream + dwMemPos)) == 0x4E454C50)
92
94
  {
95
+ if (dwMemPos + 10 > dwMemLength) return TRUE;
93
96
  norders = lpStream[dwMemPos+9];
94
97
  dwMemPos += bswapBE32(*((DWORD *)(lpStream + dwMemPos + 4))) + 8;
95
98
  }
96
99
  // PATT
97
- if (dwMemPos >= dwMemLength) return TRUE;
100
+ if (dwMemPos + 8 > dwMemLength) return TRUE;
98
101
  if (*((DWORD *)(lpStream + dwMemPos)) == 0x54544150)
99
102
  {
100
103
  UINT orderlen = norders;
101
104
  if (orderlen >= MAX_ORDERS) orderlen = MAX_ORDERS-1;
102
- for (UINT i=0; i<orderlen; i++) _this->Order[i] = lpStream[dwMemPos+10+i];
105
+ if (dwMemPos + 8 + orderlen > dwMemLength) return TRUE;
106
+ for (UINT i=0; i<orderlen; i++) _this->Order[i] = lpStream[dwMemPos+8+i];
103
107
  for (UINT j=orderlen; j>1; j--) { if (_this->Order[j-1]) break; _this->Order[j-1] = 0xFF; }
104
108
  dwMemPos += bswapBE32(*((DWORD *)(lpStream + dwMemPos + 4))) + 8;
105
109
  }