gosu 1.3.0 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) 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 +104 -70
  87. data/dependencies/SDL_sound/SDL_sound.h +6 -6
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +32 -32
  89. data/dependencies/SDL_sound/SDL_sound_au.c +14 -14
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +6 -7
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +28 -30
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +21 -14
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +26 -28
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +20 -36
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +15 -16
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +11 -10
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +20 -18
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +11 -9
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +49 -43
  100. data/dependencies/SDL_sound/dr_flac.h +10925 -4466
  101. data/dependencies/SDL_sound/dr_mp3.h +2802 -844
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +63 -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 +12 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +103 -44
  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 +61 -61
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +94 -58
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -11
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +50 -19
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +59 -28
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +104 -79
  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 +4 -3
  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 +32 -19
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +76 -160
  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 +504 -329
  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 +4848 -0
  137. data/dependencies/stb/stb_image.h +208 -73
  138. data/dependencies/stb/stb_image_write.h +57 -23
  139. data/dependencies/stb/stb_truetype.h +345 -279
  140. data/dependencies/utf8proc/utf8proc.c +37 -18
  141. data/dependencies/utf8proc/utf8proc.h +17 -5
  142. data/dependencies/utf8proc/utf8proc_data.h +12012 -10089
  143. data/ext/gosu/extconf.rb +29 -30
  144. data/include/Gosu/Audio.hpp +70 -85
  145. data/include/Gosu/Buttons.hpp +103 -103
  146. data/include/Gosu/Color.hpp +19 -11
  147. data/include/Gosu/Directories.hpp +31 -24
  148. data/include/Gosu/Font.hpp +42 -44
  149. data/include/Gosu/Gosu.hpp +5 -8
  150. data/include/Gosu/Graphics.hpp +58 -71
  151. data/include/Gosu/GraphicsBase.hpp +26 -33
  152. data/include/Gosu/IO.hpp +0 -3
  153. data/include/Gosu/Image.hpp +56 -62
  154. data/include/Gosu/ImageData.hpp +23 -27
  155. data/include/Gosu/Inspection.hpp +1 -4
  156. data/include/Gosu/Math.hpp +0 -3
  157. data/include/Gosu/TextInput.hpp +34 -40
  158. data/include/Gosu/Timing.hpp +2 -8
  159. data/include/Gosu/Version.hpp +2 -2
  160. data/include/Gosu/Window.hpp +71 -70
  161. data/lib/SDL2.dll +0 -0
  162. data/lib/gosu/compat.rb +24 -37
  163. data/lib/gosu.rb +2 -2
  164. data/lib64/SDL2.dll +0 -0
  165. data/src/Audio.cpp +88 -86
  166. data/src/AudioFile.hpp +6 -6
  167. data/src/AudioFileAudioToolbox.cpp +1 -1
  168. data/src/AudioFileSDLSound.cpp +1 -1
  169. data/src/AudioImpl.cpp +0 -7
  170. data/src/AudioImpl.hpp +6 -8
  171. data/src/BitmapIO.cpp +23 -22
  172. data/src/BlockAllocator.cpp +2 -1
  173. data/src/Channel.cpp +22 -20
  174. data/src/Color.cpp +12 -9
  175. data/src/DirectoriesApple.cpp +25 -24
  176. data/src/DirectoriesUnix.cpp +14 -12
  177. data/src/DirectoriesWin.cpp +26 -30
  178. data/src/EmptyImageData.hpp +15 -17
  179. data/src/FileUnix.cpp +1 -1
  180. data/src/FileWin.cpp +1 -1
  181. data/src/Font.cpp +59 -54
  182. data/src/Graphics.cpp +135 -143
  183. data/src/Image.cpp +41 -47
  184. data/src/Input.cpp +1 -1
  185. data/src/InputUIKit.cpp +1 -1
  186. data/src/LargeImageData.cpp +108 -101
  187. data/src/LargeImageData.hpp +17 -15
  188. data/src/Log.hpp +6 -6
  189. data/src/Macro.cpp +35 -37
  190. data/src/Macro.hpp +11 -11
  191. data/src/Math.cpp +8 -1
  192. data/src/Resolution.cpp +12 -7
  193. data/src/RubyGosu.cxx +11 -39
  194. data/src/TexChunk.cpp +50 -41
  195. data/src/TexChunk.hpp +22 -22
  196. data/src/Text.cpp +37 -37
  197. data/src/TextBuilder.cpp +60 -57
  198. data/src/TextBuilder.hpp +20 -20
  199. data/src/TextInput.cpp +127 -135
  200. data/src/TimingApple.cpp +1 -7
  201. data/src/TimingUnix.cpp +0 -6
  202. data/src/TimingWin.cpp +0 -6
  203. data/src/TrueTypeFont.cpp +107 -107
  204. data/src/TrueTypeFont.hpp +39 -38
  205. data/src/TrueTypeFontApple.cpp +19 -22
  206. data/src/TrueTypeFontUnix.cpp +21 -26
  207. data/src/TrueTypeFontWin.cpp +30 -30
  208. data/src/Window.cpp +97 -87
  209. data/src/WindowUIKit.cpp +46 -49
  210. metadata +7 -17
  211. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  212. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  213. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  214. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  215. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  216. data/dependencies/al_soft/AL/alext.h +0 -585
  217. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  218. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  219. data/dependencies/al_soft/AL/efx.h +0 -762
  220. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  221. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  222. data/lib/OpenAL32.dll +0 -0
  223. data/lib64/OpenAL32.dll +0 -0
@@ -77,18 +77,19 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
77
77
  //---------------------------------------------------------------
78
78
  {
79
79
  const DMFHEADER *pfh = (DMFHEADER *)lpStream;
80
- DMFINFO *psi;
81
- DMFSEQU *sequ;
80
+ const DMFINFO *psi;
81
+ const DMFPATT *patt;
82
+ const DMFSEQU *sequ;
82
83
  DWORD dwMemPos;
83
84
  BYTE infobyte[32];
84
- BYTE smplflags[MAX_SAMPLES], hasSMPI = 0;
85
+ BYTE smplflags[MAX_SAMPLES], hasSMPI = 0, hasSMPD = 0;
85
86
 
86
87
  if ((!lpStream) || (dwMemLength < 1024)) return FALSE;
87
88
  if ((pfh->id != 0x464d4444) || (!pfh->version) || (pfh->version & 0xF0)) return FALSE;
88
89
  dwMemPos = 66;
89
90
  _this->m_nType = MOD_TYPE_DMF;
90
91
  _this->m_nChannels = 0;
91
- while (dwMemPos + 7 < dwMemLength)
92
+ while (dwMemPos < dwMemLength - 7)
92
93
  {
93
94
  DWORD id = *((LPDWORD)(lpStream+dwMemPos));
94
95
 
@@ -100,16 +101,17 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
100
101
  case 0x47534d43:
101
102
  psi = (DMFINFO *)(lpStream+dwMemPos);
102
103
  if (id == 0x47534d43) dwMemPos++;
103
- if ((psi->infosize > dwMemLength) || (psi->infosize + dwMemPos + 8 > dwMemLength)) goto dmfexit;
104
+ if ((psi->infosize > dwMemLength) || (dwMemPos + 8 > dwMemLength - psi->infosize)) goto dmfexit;
104
105
  dwMemPos += psi->infosize + 8 - 1;
105
106
  break;
106
107
 
107
108
  // "SEQU"
108
109
  case 0x55514553:
109
110
  sequ = (DMFSEQU *)(lpStream+dwMemPos);
110
- if ((sequ->seqsize >= dwMemLength) || (dwMemPos + sequ->seqsize + 12 > dwMemLength)) goto dmfexit;
111
+ if ((sequ->seqsize >= dwMemLength) || (dwMemPos + 8 > dwMemLength - sequ->seqsize)) goto dmfexit;
112
+ if (sequ->seqsize >= 4)
111
113
  {
112
- UINT nseq = sequ->seqsize >> 1;
114
+ UINT nseq = (sequ->seqsize - 4) >> 1;
113
115
  if (nseq >= MAX_ORDERS-1) nseq = MAX_ORDERS-1;
114
116
  if (sequ->loopstart < nseq) _this->m_nRestartPos = sequ->loopstart;
115
117
  for (UINT i=0; i<nseq; i++) _this->Order[i] = (BYTE)sequ->sequ[i];
@@ -119,12 +121,12 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
119
121
 
120
122
  // "PATT"
121
123
  case 0x54544150:
122
- if (!_this->m_nChannels)
124
+ patt = (DMFPATT *)(lpStream+dwMemPos);
125
+ if ((patt->patsize >= dwMemLength) || (dwMemPos + 8 > dwMemLength - patt->patsize)) goto dmfexit;
126
+ if (patt->patsize >= 4 && !_this->m_nChannels)
123
127
  {
124
- DMFPATT *patt = (DMFPATT *)(lpStream+dwMemPos);
125
128
  UINT numpat;
126
129
  DWORD dwPos = dwMemPos + 11;
127
- if ((patt->patsize >= dwMemLength) || (dwMemPos + patt->patsize + 8 > dwMemLength)) goto dmfexit;
128
130
  numpat = patt->numpat;
129
131
  if (numpat > MAX_PATTERNS) numpat = MAX_PATTERNS;
130
132
  _this->m_nChannels = patt->tracks;
@@ -133,14 +135,15 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
133
135
  if (_this->m_nChannels < 4) _this->m_nChannels = 4;
134
136
  for (UINT npat=0; npat<numpat; npat++)
135
137
  {
136
- DMFTRACK *pt = (DMFTRACK *)(lpStream+dwPos);
138
+ const DMFTRACK *pt = (DMFTRACK *)(lpStream+dwPos);
139
+ if (dwPos + 8 >= dwMemLength) break;
137
140
  UINT tracks = pt->tracks;
138
141
  if (tracks > 32) tracks = 32;
139
142
  UINT ticks = pt->ticks;
140
143
  if (ticks > 256) ticks = 256;
141
144
  if (ticks < 16) ticks = 16;
142
145
  dwPos += 8;
143
- if ((pt->jmpsize >= dwMemLength) || (dwPos + pt->jmpsize + 4 >= dwMemLength)) break;
146
+ if ((pt->jmpsize >= dwMemLength) || (dwPos + 4 > dwMemLength - pt->jmpsize)) break;
144
147
  _this->PatternSize[npat] = (WORD)ticks;
145
148
  MODCOMMAND *m = CSoundFile_AllocatePattern(_this->PatternSize[npat], _this->m_nChannels);
146
149
  if (!m) goto dmfexit;
@@ -159,6 +162,7 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
159
162
  // Parse track global effects
160
163
  if (!glbinfobyte)
161
164
  {
165
+ if (d+1 > dwPos) break;
162
166
  BYTE info = lpStream[d++];
163
167
  BYTE infoval = 0;
164
168
  if ((info & 0x80) && (d < dwPos)) glbinfobyte = lpStream[d++];
@@ -177,18 +181,25 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
177
181
  // Parse channels
178
182
  for (UINT i=0; i<tracks; i++) if (!infobyte[i])
179
183
  {
184
+ if (d+1 > dwPos) break;
180
185
  MODCOMMAND cmd;
181
- SDL_zero(cmd);
186
+ SDL_zero(cmd);
182
187
  BYTE info = lpStream[d++];
183
- if (info & 0x80) infobyte[i] = lpStream[d++];
188
+ if (info & 0x80)
189
+ {
190
+ if (d+1 > dwPos) break;
191
+ infobyte[i] = lpStream[d++];
192
+ }
184
193
  // Instrument
185
194
  if (info & 0x40)
186
195
  {
196
+ if (d+1 > dwPos) break;
187
197
  cmd.instr = lpStream[d++];
188
198
  }
189
199
  // Note
190
200
  if (info & 0x20)
191
201
  {
202
+ if (d+1 > dwPos) break;
192
203
  cmd.note = lpStream[d++];
193
204
  if ((cmd.note) && (cmd.note < 0xfe)) cmd.note &= 0x7f;
194
205
  if ((cmd.note) && (cmd.note < 128)) cmd.note += 24;
@@ -196,12 +207,15 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
196
207
  // Volume
197
208
  if (info & 0x10)
198
209
  {
210
+ if (d+1 > dwPos) break;
199
211
  cmd.volcmd = VOLCMD_VOLUME;
200
212
  cmd.vol = (lpStream[d++]+3)>>2;
201
213
  }
202
214
  // Effect 1
203
215
  if (info & 0x08)
204
216
  {
217
+ if (d+2 > dwPos) break;
218
+
205
219
  BYTE efx = lpStream[d++];
206
220
  BYTE eval = lpStream[d++];
207
221
  switch(efx)
@@ -220,6 +234,8 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
220
234
  // Effect 2
221
235
  if (info & 0x04)
222
236
  {
237
+ if (d+2 > dwPos) break;
238
+
223
239
  BYTE efx = lpStream[d++];
224
240
  BYTE eval = lpStream[d++];
225
241
  switch(efx)
@@ -240,12 +256,15 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
240
256
  case 8: cmd.command = CMD_VIBRATO; cmd.param = eval; break;
241
257
  // 12: Note cut
242
258
  case 12: if (eval & 0xe0) { cmd.command = CMD_S3MCMDEX; cmd.param = (eval>>5)|0xc0; }
243
- else if (!cmd.note) { cmd.note = 0xfe; } break;
259
+ else if (!cmd.note) { cmd.note = 0xfe; }
260
+ break;
244
261
  }
245
262
  }
246
263
  // Effect 3
247
264
  if (info & 0x02)
248
265
  {
266
+ if (d+2 > dwPos) break;
267
+
249
268
  BYTE efx = lpStream[d++];
250
269
  BYTE eval = lpStream[d++];
251
270
  switch(efx)
@@ -316,27 +335,29 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
316
335
  }
317
336
  if (dwPos + 8 >= dwMemLength) break;
318
337
  }
319
- dwMemPos += patt->patsize + 8;
320
338
  }
339
+ dwMemPos += patt->patsize + 8;
321
340
  break;
322
341
 
323
342
  // "SMPI": Sample Info
324
343
  case 0x49504d53:
325
344
  {
326
345
  hasSMPI = 1;
327
- DMFSMPI *pds = (DMFSMPI *)(lpStream+dwMemPos);
328
- if (pds->size <= dwMemLength - dwMemPos)
346
+ const DMFSMPI *pds = (DMFSMPI *)(lpStream+dwMemPos);
347
+ if ((pds->size >= dwMemLength) || (dwMemPos + 8 > dwMemLength - pds->size)) goto dmfexit;
348
+ if (pds->size >= 1)
329
349
  {
330
350
  DWORD dwPos = dwMemPos + 9;
331
351
  _this->m_nSamples = pds->samples;
332
352
  if (_this->m_nSamples >= MAX_SAMPLES) _this->m_nSamples = MAX_SAMPLES-1;
333
353
  for (UINT iSmp=1; iSmp<=_this->m_nSamples; iSmp++)
334
354
  {
355
+ if (dwPos >= dwMemPos + pds->size + 8) break;
335
356
  const UINT namelen = lpStream[dwPos];
336
357
  smplflags[iSmp] = 0;
337
358
  if (dwPos+namelen+1+sizeof(DMFSAMPLE) > dwMemPos+pds->size+8) break;
338
359
  dwPos += namelen + 1;
339
- DMFSAMPLE *psh = (DMFSAMPLE *)(lpStream+dwPos);
360
+ const DMFSAMPLE *psh = (DMFSAMPLE *)(lpStream+dwPos);
340
361
  MODINSTRUMENT *psmp = &_this->Ins[iSmp];
341
362
  psmp->nLength = psh->len;
342
363
  psmp->nLoopStart = psh->loopstart;
@@ -360,7 +381,7 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
360
381
  {
361
382
  DWORD dwPos = dwMemPos + 8;
362
383
  UINT ismpd = 0;
363
- for (UINT iSmp=1; iSmp<=_this->m_nSamples; iSmp++)
384
+ for (UINT iSmp=1; iSmp<=_this->m_nSamples && !hasSMPD; iSmp++)
364
385
  {
365
386
  ismpd++;
366
387
  DWORD pksize;
@@ -383,6 +404,7 @@ BOOL CSoundFile_ReadDMF(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
383
404
  }
384
405
  dwPos += pksize;
385
406
  }
407
+ hasSMPD = 1;
386
408
  dwMemPos = dwPos;
387
409
  }
388
410
  break;
@@ -435,7 +457,7 @@ typedef struct DMF_HTREE
435
457
 
436
458
 
437
459
  // DMF Huffman ReadBits
438
- BYTE DMFReadBits(DMF_HTREE *tree, UINT nbits)
460
+ static BYTE DMFReadBits(DMF_HTREE *tree, UINT nbits)
439
461
  //-------------------------------------------
440
462
  {
441
463
  BYTE x = 0, bitv = 1;
@@ -445,8 +467,8 @@ BYTE DMFReadBits(DMF_HTREE *tree, UINT nbits)
445
467
  {
446
468
  tree->bitnum--;
447
469
  } else
448
- {
449
- tree->bitbuf = (tree->ibuf < tree->ibufmax) ? *(tree->ibuf++) : 0;
470
+ if (tree->ibuf < tree->ibufmax) {
471
+ tree->bitbuf = *(tree->ibuf++);
450
472
  tree->bitnum = 7;
451
473
  }
452
474
  if (tree->bitbuf & 1) x |= bitv;
@@ -460,7 +482,7 @@ BYTE DMFReadBits(DMF_HTREE *tree, UINT nbits)
460
482
  // tree: [8-bit value][12-bit index][12-bit index] = 32-bit
461
483
  //
462
484
 
463
- void DMFNewNode(DMF_HTREE *tree)
485
+ static void DMFNewNode(DMF_HTREE *tree)
464
486
  //------------------------------
465
487
  {
466
488
  BYTE isleft, isright;
@@ -501,14 +523,22 @@ int DMFUnpack(LPBYTE psample, LPBYTE ibuf, LPBYTE ibufmax, UINT maxlen)
501
523
  DMF_HTREE tree;
502
524
  UINT actnode;
503
525
  BYTE value, sign, delta = 0;
504
-
526
+
505
527
  SDL_memset(&tree, 0, sizeof(tree));
506
528
  tree.ibuf = ibuf;
507
529
  tree.ibufmax = ibufmax;
508
530
  DMFNewNode(&tree);
509
531
  value = 0;
532
+
533
+ if (tree.ibuf >= ibufmax) return tree.ibuf - ibuf;
534
+
510
535
  for (UINT i=0; i<maxlen; i++)
511
536
  {
537
+ if ((tree.ibuf >= tree.ibufmax) && (!tree.bitnum))
538
+ {
539
+ /* unexpected EOF */
540
+ break;
541
+ }
512
542
  actnode = 0;
513
543
  sign = DMFReadBits(&tree, 1);
514
544
  do
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  ////////////////////////////////////////
8
- // Farandole (FAR) module loader //
8
+ // Farandole (FAR) module loader //
9
9
  ////////////////////////////////////////
10
10
  #include "libmodplug.h"
11
11
 
@@ -102,8 +102,6 @@ BOOL CSoundFile_ReadFAR(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
102
102
  dwMemPos += headerlen - (869 + stlen);
103
103
  if (dwMemPos >= dwMemLength) return TRUE;
104
104
 
105
- // end byteswap of pattern data
106
-
107
105
  WORD *patsiz = (WORD *)pmh2->patsiz;
108
106
  for (UINT ipat=0; ipat<256; ipat++) if (patsiz[ipat])
109
107
  {
@@ -114,6 +112,7 @@ BOOL CSoundFile_ReadFAR(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
114
112
  continue;
115
113
  }
116
114
  if (dwMemPos + patlen >= dwMemLength) return TRUE;
115
+ UINT max = (patlen - 2) & ~3;
117
116
  UINT rows = (patlen - 2) >> 6;
118
117
  if (!rows)
119
118
  {
@@ -122,13 +121,12 @@ BOOL CSoundFile_ReadFAR(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
122
121
  }
123
122
  if (rows > 256) rows = 256;
124
123
  if (rows < 16) rows = 16;
124
+ if (max > rows*16*4) max = rows*16*4;
125
125
  _this->PatternSize[ipat] = rows;
126
126
  if ((_this->Patterns[ipat] = CSoundFile_AllocatePattern(rows, _this->m_nChannels)) == NULL) return TRUE;
127
127
  MODCOMMAND *m = _this->Patterns[ipat];
128
128
  UINT patbrk = lpStream[dwMemPos];
129
129
  const BYTE *p = lpStream + dwMemPos + 2;
130
- UINT max = rows*16*4;
131
- if (max > patlen-2) max = patlen-2;
132
130
  for (UINT len=0; len<max; len += 4, m++)
133
131
  {
134
132
  BYTE note = p[len];
@@ -140,11 +138,10 @@ BOOL CSoundFile_ReadFAR(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
140
138
  m->instr = ins + 1;
141
139
  m->note = note + 36;
142
140
  }
143
- if (vol & 0x0F)
141
+ if (vol >= 0x01 && vol <= 0x10)
144
142
  {
145
143
  m->volcmd = VOLCMD_VOLUME;
146
- m->vol = (vol & 0x0F) << 2;
147
- if (m->vol <= 4) m->vol = 0;
144
+ m->vol = (vol - 1) << 2;
148
145
  }
149
146
  switch(eff & 0xF0)
150
147
  {
@@ -224,10 +221,10 @@ BOOL CSoundFile_ReadFAR(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
224
221
  const FARSAMPLE *pfs = (const FARSAMPLE*)(lpStream + dwMemPos);
225
222
  dwMemPos += sizeof(FARSAMPLE);
226
223
  _this->m_nSamples = ismp + 1;
227
- const DWORD length = bswapLE32( pfs->length ) ; /* endian fix - Toad */
228
- pins->nLength = length ;
229
- pins->nLoopStart = bswapLE32(pfs->reppos) ;
230
- pins->nLoopEnd = bswapLE32(pfs->repend) ;
224
+ const DWORD length = bswapLE32(pfs->length); /* endian fix - Toad */
225
+ pins->nLength = length;
226
+ pins->nLoopStart = bswapLE32(pfs->reppos);
227
+ pins->nLoopEnd = bswapLE32(pfs->repend);
231
228
  pins->nFineTune = 0;
232
229
  pins->nC4Speed = 8363*2;
233
230
  pins->nGlobalVol = 64;
@@ -250,4 +247,3 @@ BOOL CSoundFile_ReadFAR(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
250
247
  }
251
248
  return TRUE;
252
249
  }
253
-