koffi 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/ChangeLog.md +6 -0
  2. package/build/qemu/2.1.2/koffi_darwin_arm64.tar.gz +0 -0
  3. package/build/qemu/2.1.2/koffi_darwin_x64.tar.gz +0 -0
  4. package/build/qemu/2.1.2/koffi_freebsd_arm64.tar.gz +0 -0
  5. package/build/qemu/2.1.2/koffi_freebsd_ia32.tar.gz +0 -0
  6. package/build/qemu/2.1.2/koffi_freebsd_x64.tar.gz +0 -0
  7. package/build/qemu/2.1.2/koffi_linux_arm32hf.tar.gz +0 -0
  8. package/build/qemu/2.1.2/koffi_linux_arm64.tar.gz +0 -0
  9. package/build/qemu/2.1.2/koffi_linux_ia32.tar.gz +0 -0
  10. package/build/qemu/2.1.2/koffi_linux_riscv64hf64.tar.gz +0 -0
  11. package/build/qemu/2.1.2/koffi_linux_x64.tar.gz +0 -0
  12. package/build/qemu/2.1.2/koffi_openbsd_ia32.tar.gz +0 -0
  13. package/build/qemu/2.1.2/koffi_openbsd_x64.tar.gz +0 -0
  14. package/build/qemu/2.1.2/koffi_win32_arm64.tar.gz +0 -0
  15. package/build/qemu/2.1.2/koffi_win32_ia32.tar.gz +0 -0
  16. package/build/qemu/2.1.2/koffi_win32_x64.tar.gz +0 -0
  17. package/doc/templates/badges.html +3 -0
  18. package/package.json +2 -2
  19. package/src/abi_arm64.cc +35 -1
  20. package/src/abi_x64_win.cc +2 -8
  21. package/src/abi_x86.cc +1 -7
  22. package/src/ffi.hh +1 -1
  23. package/src/util.hh +6 -0
  24. package/test/raylib.js +37 -5
  25. package/vendor/libcc/libcc.cc +430 -196
  26. package/vendor/libcc/libcc.hh +1417 -1283
  27. package/vendor/raylib/BINDINGS.md +87 -70
  28. package/vendor/raylib/CHANGELOG +263 -50
  29. package/vendor/raylib/CMakeLists.txt +12 -0
  30. package/vendor/raylib/CMakeOptions.txt +8 -1
  31. package/vendor/raylib/CONVENTIONS.md +2 -3
  32. package/vendor/raylib/FAQ.md +137 -0
  33. package/vendor/raylib/HISTORY.md +62 -29
  34. package/vendor/raylib/LICENSE +1 -1
  35. package/vendor/raylib/README.md +22 -17
  36. package/vendor/raylib/ROADMAP.md +8 -7
  37. package/vendor/raylib/cmake/CompileDefinitions.cmake +19 -15
  38. package/vendor/raylib/cmake/GlfwImport.cmake +2 -0
  39. package/vendor/raylib/cmake/LibraryConfigurations.cmake +22 -16
  40. package/vendor/raylib/cmake/raylib-config.cmake +52 -49
  41. package/vendor/raylib/examples/CMakeLists.txt +14 -9
  42. package/vendor/raylib/examples/Makefile +112 -125
  43. package/vendor/raylib/examples/Makefile.Android +1 -1
  44. package/vendor/raylib/examples/Makefile.Web +145 -158
  45. package/vendor/raylib/examples/README.md +141 -141
  46. package/vendor/raylib/examples/audio/audio_module_playing.c +9 -4
  47. package/vendor/raylib/examples/audio/audio_multichannel_sound.c +8 -3
  48. package/vendor/raylib/examples/audio/audio_music_stream.c +16 -11
  49. package/vendor/raylib/examples/audio/audio_raw_stream.c +57 -9
  50. package/vendor/raylib/examples/audio/audio_sound_loading.c +8 -3
  51. package/vendor/raylib/examples/audio/audio_stream_effects.c +179 -0
  52. package/vendor/raylib/examples/audio/audio_stream_effects.png +0 -0
  53. package/vendor/raylib/examples/build.zig +17 -6
  54. package/vendor/raylib/examples/core/core_2d_camera.c +8 -4
  55. package/vendor/raylib/examples/core/core_2d_camera_mouse_zoom.c +105 -0
  56. package/vendor/raylib/examples/core/core_2d_camera_mouse_zoom.png +0 -0
  57. package/vendor/raylib/examples/core/core_2d_camera_platformer.c +11 -6
  58. package/vendor/raylib/examples/core/core_3d_camera_first_person.c +9 -4
  59. package/vendor/raylib/examples/core/core_3d_camera_free.c +9 -4
  60. package/vendor/raylib/examples/core/core_3d_camera_mode.c +8 -3
  61. package/vendor/raylib/examples/core/core_3d_picking.c +9 -4
  62. package/vendor/raylib/examples/core/core_basic_screen_manager.c +9 -7
  63. package/vendor/raylib/examples/core/core_basic_window.c +8 -3
  64. package/vendor/raylib/examples/core/core_basic_window_web.c +13 -11
  65. package/vendor/raylib/examples/core/core_custom_frame_control.c +9 -4
  66. package/vendor/raylib/examples/core/core_custom_logging.c +12 -8
  67. package/vendor/raylib/examples/core/core_drop_files.c +20 -12
  68. package/vendor/raylib/examples/core/core_input_gamepad.c +20 -15
  69. package/vendor/raylib/examples/core/core_input_gestures.c +19 -15
  70. package/vendor/raylib/examples/core/core_input_keys.c +8 -3
  71. package/vendor/raylib/examples/core/core_input_mouse.c +8 -3
  72. package/vendor/raylib/examples/core/core_input_mouse_wheel.c +8 -3
  73. package/vendor/raylib/examples/core/core_input_multitouch.c +8 -3
  74. package/vendor/raylib/examples/core/core_loading_thread.c +10 -6
  75. package/vendor/raylib/examples/core/core_random_values.c +8 -3
  76. package/vendor/raylib/examples/core/core_scissor_test.c +8 -3
  77. package/vendor/raylib/examples/core/core_smooth_pixelperfect.c +9 -4
  78. package/vendor/raylib/examples/core/core_split_screen.c +8 -3
  79. package/vendor/raylib/examples/core/core_storage_values.c +109 -3
  80. package/vendor/raylib/examples/core/core_vr_simulator.c +15 -7
  81. package/vendor/raylib/examples/core/core_window_flags.c +8 -3
  82. package/vendor/raylib/examples/core/core_window_letterbox.c +13 -18
  83. package/vendor/raylib/examples/core/core_window_should_close.c +77 -0
  84. package/vendor/raylib/examples/core/core_window_should_close.png +0 -0
  85. package/vendor/raylib/examples/core/core_world_screen.c +9 -4
  86. package/vendor/raylib/examples/examples_template.c +8 -3
  87. package/vendor/raylib/examples/models/models_animation.c +11 -7
  88. package/vendor/raylib/examples/models/models_billboard.c +9 -4
  89. package/vendor/raylib/examples/models/models_box_collisions.c +8 -3
  90. package/vendor/raylib/examples/models/models_cubicmap.c +9 -4
  91. package/vendor/raylib/examples/models/models_first_person_maze.c +9 -4
  92. package/vendor/raylib/examples/models/models_geometric_shapes.c +8 -3
  93. package/vendor/raylib/examples/models/models_heightmap.c +9 -4
  94. package/vendor/raylib/examples/models/models_loading.c +21 -17
  95. package/vendor/raylib/examples/models/models_loading_gltf.c +15 -41
  96. package/vendor/raylib/examples/models/models_loading_vox.c +9 -4
  97. package/vendor/raylib/examples/models/models_mesh_generation.c +71 -58
  98. package/vendor/raylib/examples/models/models_mesh_picking.c +25 -7
  99. package/vendor/raylib/examples/models/models_orthographic_projection.c +8 -5
  100. package/vendor/raylib/examples/models/models_rlgl_solar_system.c +6 -4
  101. package/vendor/raylib/examples/models/models_skybox.c +16 -12
  102. package/vendor/raylib/examples/models/models_waving_cubes.c +9 -4
  103. package/vendor/raylib/examples/models/models_yaw_pitch_roll.c +12 -7
  104. package/vendor/raylib/examples/models/resources/LICENSE.md +9 -10
  105. package/vendor/raylib/examples/models/resources/models/gltf/LICENSE +2 -23
  106. package/vendor/raylib/examples/models/resources/models/gltf/{raylib_32x32.glb → raylib_logo_3d.glb} +0 -0
  107. package/vendor/raylib/examples/models/resources/models/gltf/robot.blend +0 -0
  108. package/vendor/raylib/examples/models/resources/models/gltf/robot.glb +0 -0
  109. package/vendor/raylib/examples/others/easings_testbed.c +10 -8
  110. package/vendor/raylib/examples/others/easings_testbed.png +0 -0
  111. package/vendor/raylib/examples/others/embedded_files_loading.c +10 -5
  112. package/vendor/raylib/examples/others/embedded_files_loading.png +0 -0
  113. package/vendor/raylib/examples/others/raylib_opengl_interop.c +10 -6
  114. package/vendor/raylib/{src/extras/easings.h → examples/others/reasings.h} +38 -38
  115. package/vendor/raylib/examples/others/rlgl_compute_shader.c +21 -20
  116. package/vendor/raylib/examples/others/rlgl_compute_shader.png +0 -0
  117. package/vendor/raylib/examples/others/rlgl_standalone.c +4 -4
  118. package/vendor/raylib/examples/others/rlgl_standalone.png +0 -0
  119. package/vendor/raylib/examples/raylib_compile_execute.bat +2 -2
  120. package/vendor/raylib/examples/shaders/resources/shaders/glsl330/lighting.fs +1 -1
  121. package/vendor/raylib/examples/shaders/resources/shaders/glsl330/{base_lighting_instanced.vs → lighting_instancing.vs} +2 -2
  122. package/vendor/raylib/examples/shaders/rlights.h +14 -27
  123. package/vendor/raylib/examples/shaders/shaders_basic_lighting.c +24 -26
  124. package/vendor/raylib/examples/shaders/shaders_custom_uniform.c +10 -5
  125. package/vendor/raylib/examples/shaders/shaders_eratosthenes.c +13 -8
  126. package/vendor/raylib/examples/shaders/shaders_fog.c +8 -12
  127. package/vendor/raylib/examples/shaders/shaders_hot_reloading.c +10 -5
  128. package/vendor/raylib/examples/shaders/shaders_julia_set.c +9 -4
  129. package/vendor/raylib/examples/shaders/shaders_mesh_instancing.c +45 -119
  130. package/vendor/raylib/examples/shaders/shaders_model_shader.c +10 -5
  131. package/vendor/raylib/examples/shaders/shaders_multi_sample2d.c +8 -3
  132. package/vendor/raylib/examples/shaders/shaders_palette_switch.c +8 -3
  133. package/vendor/raylib/examples/shaders/shaders_postprocessing.c +9 -4
  134. package/vendor/raylib/examples/shaders/shaders_raymarching.c +14 -11
  135. package/vendor/raylib/examples/shaders/shaders_shapes_textures.c +8 -3
  136. package/vendor/raylib/examples/shaders/shaders_simple_mask.c +10 -5
  137. package/vendor/raylib/examples/shaders/shaders_spotlight.c +10 -6
  138. package/vendor/raylib/examples/shaders/shaders_texture_drawing.c +9 -4
  139. package/vendor/raylib/examples/shaders/shaders_texture_outline.c +8 -3
  140. package/vendor/raylib/examples/shaders/shaders_texture_waves.c +8 -3
  141. package/vendor/raylib/{src/extras → examples/shapes}/raygui.h +1290 -1141
  142. package/vendor/raylib/examples/{others/easings.h → shapes/reasings.h} +40 -40
  143. package/vendor/raylib/examples/shapes/shapes_basic_shapes.c +8 -3
  144. package/vendor/raylib/examples/shapes/shapes_bouncing_ball.c +8 -3
  145. package/vendor/raylib/examples/shapes/shapes_collision_area.c +10 -4
  146. package/vendor/raylib/examples/shapes/shapes_colors_palette.c +8 -3
  147. package/vendor/raylib/examples/shapes/shapes_draw_circle_sector.c +9 -4
  148. package/vendor/raylib/examples/shapes/shapes_draw_rectangle_rounded.c +9 -4
  149. package/vendor/raylib/examples/shapes/shapes_draw_ring.c +10 -6
  150. package/vendor/raylib/examples/shapes/shapes_easings_ball_anim.c +9 -4
  151. package/vendor/raylib/examples/shapes/shapes_easings_box_anim.c +9 -4
  152. package/vendor/raylib/examples/shapes/shapes_easings_rectangle_array.c +9 -4
  153. package/vendor/raylib/examples/shapes/shapes_following_eyes.c +8 -3
  154. package/vendor/raylib/examples/shapes/shapes_lines_bezier.c +8 -3
  155. package/vendor/raylib/examples/shapes/shapes_logo_raylib.c +8 -3
  156. package/vendor/raylib/examples/shapes/shapes_logo_raylib_anim.c +8 -3
  157. package/vendor/raylib/examples/shapes/shapes_rectangle_scaling.c +14 -5
  158. package/vendor/raylib/examples/shapes/shapes_top_down_lights.c +355 -0
  159. package/vendor/raylib/examples/shapes/shapes_top_down_lights.png +0 -0
  160. package/vendor/raylib/examples/text/resources/DotGothic16-Regular.ttf +0 -0
  161. package/vendor/raylib/examples/text/resources/DotGothic16-Regular_OFL.txt +93 -0
  162. package/vendor/raylib/examples/text/resources/LICENSE.md +1 -1
  163. package/vendor/raylib/examples/text/text_codepoints_loading.c +138 -0
  164. package/vendor/raylib/examples/text/text_codepoints_loading.png +0 -0
  165. package/vendor/raylib/examples/text/text_draw_3d.c +42 -33
  166. package/vendor/raylib/examples/text/text_font_filters.c +14 -11
  167. package/vendor/raylib/examples/text/text_font_loading.c +9 -4
  168. package/vendor/raylib/examples/text/text_font_sdf.c +9 -4
  169. package/vendor/raylib/examples/text/text_font_spritefont.c +12 -6
  170. package/vendor/raylib/examples/text/text_format_text.c +8 -3
  171. package/vendor/raylib/examples/text/text_input_box.c +8 -3
  172. package/vendor/raylib/examples/text/text_raylib_fonts.c +9 -4
  173. package/vendor/raylib/examples/text/text_rectangle_bounds.c +9 -5
  174. package/vendor/raylib/examples/text/text_unicode.c +9 -7
  175. package/vendor/raylib/examples/text/text_writing_anim.c +8 -3
  176. package/vendor/raylib/examples/textures/resources/scarfy_run.gif +0 -0
  177. package/vendor/raylib/examples/textures/textures_background_scrolling.c +8 -3
  178. package/vendor/raylib/examples/textures/textures_blend_modes.c +8 -3
  179. package/vendor/raylib/examples/textures/textures_bunnymark.c +8 -3
  180. package/vendor/raylib/examples/textures/textures_draw_tiled.c +14 -10
  181. package/vendor/raylib/examples/textures/textures_fog_of_war.c +154 -0
  182. package/vendor/raylib/examples/textures/textures_fog_of_war.png +0 -0
  183. package/vendor/raylib/examples/textures/textures_gif_player.c +121 -0
  184. package/vendor/raylib/examples/textures/textures_gif_player.png +0 -0
  185. package/vendor/raylib/examples/textures/textures_image_drawing.c +8 -3
  186. package/vendor/raylib/examples/textures/textures_image_generation.c +8 -3
  187. package/vendor/raylib/examples/textures/textures_image_loading.c +8 -3
  188. package/vendor/raylib/examples/textures/textures_image_processing.c +8 -3
  189. package/vendor/raylib/examples/textures/textures_image_text.c +8 -3
  190. package/vendor/raylib/examples/textures/textures_logo_raylib.c +8 -3
  191. package/vendor/raylib/examples/textures/textures_mouse_painting.c +9 -4
  192. package/vendor/raylib/examples/textures/textures_npatch_drawing.c +8 -3
  193. package/vendor/raylib/examples/textures/textures_particles_blending.c +8 -3
  194. package/vendor/raylib/examples/textures/textures_polygon.c +9 -5
  195. package/vendor/raylib/examples/textures/textures_raw_data.c +8 -3
  196. package/vendor/raylib/examples/textures/{textures_rectangle.c → textures_sprite_anim.c} +11 -5
  197. package/vendor/raylib/examples/textures/{textures_rectangle.png → textures_sprite_anim.png} +0 -0
  198. package/vendor/raylib/examples/textures/textures_sprite_button.c +8 -3
  199. package/vendor/raylib/examples/textures/textures_sprite_explosion.c +8 -3
  200. package/vendor/raylib/examples/textures/textures_srcrec_dstrec.c +8 -3
  201. package/vendor/raylib/examples/textures/textures_to_image.c +8 -3
  202. package/vendor/raylib/parser/LICENSE +1 -1
  203. package/vendor/raylib/parser/Makefile +28 -0
  204. package/vendor/raylib/parser/README.md +49 -5
  205. package/vendor/raylib/parser/output/raylib_api.json +10717 -0
  206. package/vendor/raylib/parser/output/raylib_api.lua +7435 -0
  207. package/vendor/raylib/parser/{raylib_api.txt → output/raylib_api.txt} +1371 -824
  208. package/vendor/raylib/parser/{raylib_api.xml → output/raylib_api.xml} +827 -595
  209. package/vendor/raylib/parser/raylib_parser.c +1174 -196
  210. package/vendor/raylib/projects/4coder/Makefile +2 -4
  211. package/vendor/raylib/projects/4coder/main.c +0 -1
  212. package/vendor/raylib/projects/CMake/CMakeLists.txt +13 -16
  213. package/vendor/raylib/projects/CMake/README.md +27 -0
  214. package/vendor/raylib/projects/CMake/core_basic_window.c +52 -31
  215. package/vendor/raylib/projects/CodeBlocks/README.md +4 -4
  216. package/vendor/raylib/projects/Geany/core_basic_window.c +1 -1
  217. package/vendor/raylib/projects/Notepad++/c_raylib.xml +168 -128
  218. package/vendor/raylib/projects/Notepad++/npes_saved_tcc.txt +0 -0
  219. package/vendor/raylib/projects/Notepad++/npes_saved_w64devkit.txt +0 -0
  220. package/vendor/raylib/projects/Notepad++/npes_saved_zig.txt +0 -0
  221. package/vendor/raylib/projects/Notepad++/raylib_npp_parser/raylib_npp.xml +168 -84
  222. package/vendor/raylib/projects/Notepad++/raylib_npp_parser/raylib_to_parse.h +67 -51
  223. package/vendor/raylib/projects/README.md +1 -1
  224. package/vendor/raylib/projects/VSCode/.vscode/c_cpp_properties.json +1 -1
  225. package/vendor/raylib/projects/VSCode/Makefile +8 -11
  226. package/vendor/raylib/projects/VSCode/main.c +53 -26
  227. package/vendor/raylib/projects/VSCode/resources/LICENSE +1 -0
  228. package/vendor/raylib/projects/scripts/build-linux.sh +6 -6
  229. package/vendor/raylib/projects/scripts/build-osx.sh +6 -6
  230. package/vendor/raylib/projects/scripts/build-rpi.sh +6 -6
  231. package/vendor/raylib/projects/scripts/build-windows.bat +2 -2
  232. package/vendor/raylib/src/CMakeLists.txt +6 -7
  233. package/vendor/raylib/src/Makefile +209 -103
  234. package/vendor/raylib/src/build.zig +56 -20
  235. package/vendor/raylib/src/config.h +32 -27
  236. package/vendor/raylib/src/external/cgltf.h +342 -104
  237. package/vendor/raylib/src/external/dr_wav.h +487 -225
  238. package/vendor/raylib/src/external/glfw/src/posix_time.c +1 -3
  239. package/vendor/raylib/src/external/glfw/src/wl_init.c +1 -3
  240. package/vendor/raylib/src/external/jar_xm.h +2 -1
  241. package/vendor/raylib/src/external/miniaudio.h +62251 -42061
  242. package/vendor/raylib/src/external/qoi.h +671 -0
  243. package/vendor/raylib/src/external/stb_vorbis.h +1 -1
  244. package/vendor/raylib/src/external/vox_loader.h +30 -25
  245. package/vendor/raylib/src/minshell.html +82 -0
  246. package/vendor/raylib/src/raudio.c +359 -201
  247. package/vendor/raylib/src/raylib.dll.rc +5 -5
  248. package/vendor/raylib/src/raylib.dll.rc.data +0 -0
  249. package/vendor/raylib/src/raylib.h +95 -63
  250. package/vendor/raylib/src/raylib.rc +5 -5
  251. package/vendor/raylib/src/raylib.rc.data +0 -0
  252. package/vendor/raylib/src/raymath.h +391 -133
  253. package/vendor/raylib/src/rcamera.h +32 -41
  254. package/vendor/raylib/src/rcore.c +775 -471
  255. package/vendor/raylib/src/rgestures.h +5 -5
  256. package/vendor/raylib/src/rglfw.c +3 -3
  257. package/vendor/raylib/src/rlgl.h +184 -144
  258. package/vendor/raylib/src/rmodels.c +207 -144
  259. package/vendor/raylib/src/rshapes.c +105 -47
  260. package/vendor/raylib/src/rtext.c +255 -38
  261. package/vendor/raylib/src/rtextures.c +167 -71
  262. package/vendor/raylib/src/shell.html +63 -63
  263. package/vendor/raylib/src/utils.c +49 -3
  264. package/vendor/raylib/src/utils.h +3 -3
  265. package/build/qemu/2.1.1/koffi_darwin_arm64.tar.gz +0 -0
  266. package/build/qemu/2.1.1/koffi_darwin_x64.tar.gz +0 -0
  267. package/build/qemu/2.1.1/koffi_freebsd_arm64.tar.gz +0 -0
  268. package/build/qemu/2.1.1/koffi_freebsd_ia32.tar.gz +0 -0
  269. package/build/qemu/2.1.1/koffi_freebsd_x64.tar.gz +0 -0
  270. package/build/qemu/2.1.1/koffi_linux_arm32hf.tar.gz +0 -0
  271. package/build/qemu/2.1.1/koffi_linux_arm64.tar.gz +0 -0
  272. package/build/qemu/2.1.1/koffi_linux_ia32.tar.gz +0 -0
  273. package/build/qemu/2.1.1/koffi_linux_riscv64hf64.tar.gz +0 -0
  274. package/build/qemu/2.1.1/koffi_linux_x64.tar.gz +0 -0
  275. package/build/qemu/2.1.1/koffi_openbsd_ia32.tar.gz +0 -0
  276. package/build/qemu/2.1.1/koffi_openbsd_x64.tar.gz +0 -0
  277. package/build/qemu/2.1.1/koffi_win32_arm64.tar.gz +0 -0
  278. package/build/qemu/2.1.1/koffi_win32_ia32.tar.gz +0 -0
  279. package/build/qemu/2.1.1/koffi_win32_x64.tar.gz +0 -0
  280. package/vendor/raylib/CONTRIBUTORS.md +0 -63
  281. package/vendor/raylib/SPONSORS.md +0 -68
  282. package/vendor/raylib/examples/core/core_quat_conversion.c +0 -132
  283. package/vendor/raylib/examples/core/core_quat_conversion.png +0 -0
  284. package/vendor/raylib/examples/models/resources/models/gltf/AnimatedMorphCube.glb +0 -0
  285. package/vendor/raylib/examples/models/resources/models/gltf/AnimatedTriangle.gltf +0 -118
  286. package/vendor/raylib/examples/models/resources/models/gltf/BoxAnimated.glb +0 -0
  287. package/vendor/raylib/examples/models/resources/models/gltf/girl.glb +0 -0
  288. package/vendor/raylib/examples/models/resources/models/gltf/rigged_figure.glb +0 -0
  289. package/vendor/raylib/examples/models/resources/models/gltf/vertex_colored_object.glb +0 -0
  290. package/vendor/raylib/examples/models/resources/models/iqm/vertex_colored_object.iqm +0 -0
  291. package/vendor/raylib/examples/models/rlights.h +0 -183
  292. package/vendor/raylib/examples/others/raudio_standalone.c +0 -152
  293. package/vendor/raylib/examples/others/resources/audio/country.mp3 +0 -0
  294. package/vendor/raylib/examples/others/resources/audio/target.ogg +0 -0
  295. package/vendor/raylib/examples/others/resources/audio/weird.wav +0 -0
  296. package/vendor/raylib/examples/physics/physics_demo.c +0 -128
  297. package/vendor/raylib/examples/physics/physics_demo.png +0 -0
  298. package/vendor/raylib/examples/physics/physics_friction.c +0 -142
  299. package/vendor/raylib/examples/physics/physics_friction.png +0 -0
  300. package/vendor/raylib/examples/physics/physics_movement.c +0 -128
  301. package/vendor/raylib/examples/physics/physics_movement.png +0 -0
  302. package/vendor/raylib/examples/physics/physics_restitution.c +0 -129
  303. package/vendor/raylib/examples/physics/physics_restitution.png +0 -0
  304. package/vendor/raylib/examples/physics/physics_shatter.c +0 -111
  305. package/vendor/raylib/examples/physics/physics_shatter.png +0 -0
  306. package/vendor/raylib/parser/raylib_api.json +0 -6668
  307. package/vendor/raylib/projects/VS2019/raylib/raylib.rc +0 -0
  308. package/vendor/raylib/projects/VS2019/raylib/resource.h +0 -14
  309. package/vendor/raylib/src/extras/physac.h +0 -1977
  310. package/vendor/raylib/src/extras/rmem.h +0 -751
  311. package/vendor/raylib/src/raudio.h +0 -198
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  WAV audio loader and writer. Choice of public domain or MIT-0. See license statements at the end of this file.
3
- dr_wav - v0.13.3 - TBD
3
+ dr_wav - v0.13.4 - 2021-12-08
4
4
 
5
5
  David Reid - mackron@gmail.com
6
6
 
@@ -125,7 +125,7 @@ extern "C" {
125
125
 
126
126
  #define DRWAV_VERSION_MAJOR 0
127
127
  #define DRWAV_VERSION_MINOR 13
128
- #define DRWAV_VERSION_REVISION 2
128
+ #define DRWAV_VERSION_REVISION 4
129
129
  #define DRWAV_VERSION_STRING DRWAV_XSTRINGIFY(DRWAV_VERSION_MAJOR) "." DRWAV_XSTRINGIFY(DRWAV_VERSION_MINOR) "." DRWAV_XSTRINGIFY(DRWAV_VERSION_REVISION)
130
130
 
131
131
  #include <stddef.h> /* For size_t. */
@@ -1335,6 +1335,7 @@ DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b);
1335
1335
  #define drwav_min(a, b) (((a) < (b)) ? (a) : (b))
1336
1336
  #define drwav_max(a, b) (((a) > (b)) ? (a) : (b))
1337
1337
  #define drwav_clamp(x, lo, hi) (drwav_max((lo), drwav_min((hi), (x))))
1338
+ #define drwav_offset_ptr(p, offset) (((drwav_uint8*)(p)) + (offset))
1338
1339
 
1339
1340
  #define DRWAV_MAX_SIMD_VECTOR_SIZE 64 /* 64 for AVX-512 in the future. */
1340
1341
 
@@ -2166,13 +2167,14 @@ DRWAV_PRIVATE size_t drwav__metadata_parser_read(drwav__metadata_parser* pParser
2166
2167
  }
2167
2168
  }
2168
2169
 
2169
- DRWAV_PRIVATE drwav_uint64 drwav__read_smpl_to_metadata_obj(drwav__metadata_parser* pParser, drwav_metadata* pMetadata)
2170
+ DRWAV_PRIVATE drwav_uint64 drwav__read_smpl_to_metadata_obj(drwav__metadata_parser* pParser, const drwav_chunk_header* pChunkHeader, drwav_metadata* pMetadata)
2170
2171
  {
2171
2172
  drwav_uint8 smplHeaderData[DRWAV_SMPL_BYTES];
2172
2173
  drwav_uint64 totalBytesRead = 0;
2173
2174
  size_t bytesJustRead = drwav__metadata_parser_read(pParser, smplHeaderData, sizeof(smplHeaderData), &totalBytesRead);
2174
2175
 
2175
2176
  DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
2177
+ DRWAV_ASSERT(pChunkHeader != NULL);
2176
2178
 
2177
2179
  if (bytesJustRead == sizeof(smplHeaderData)) {
2178
2180
  drwav_uint32 iSampleLoop;
@@ -2187,36 +2189,43 @@ DRWAV_PRIVATE drwav_uint64 drwav__read_smpl_to_metadata_obj(drwav__metadata_pars
2187
2189
  pMetadata->data.smpl.smpteOffset = drwav_bytes_to_u32(smplHeaderData + 24);
2188
2190
  pMetadata->data.smpl.sampleLoopCount = drwav_bytes_to_u32(smplHeaderData + 28);
2189
2191
  pMetadata->data.smpl.samplerSpecificDataSizeInBytes = drwav_bytes_to_u32(smplHeaderData + 32);
2190
- pMetadata->data.smpl.pLoops = (drwav_smpl_loop*)drwav__metadata_get_memory(pParser, sizeof(drwav_smpl_loop) * pMetadata->data.smpl.sampleLoopCount, DRWAV_METADATA_ALIGNMENT);
2191
-
2192
- for (iSampleLoop = 0; iSampleLoop < pMetadata->data.smpl.sampleLoopCount; ++iSampleLoop) {
2193
- drwav_uint8 smplLoopData[DRWAV_SMPL_LOOP_BYTES];
2194
- bytesJustRead = drwav__metadata_parser_read(pParser, smplLoopData, sizeof(smplLoopData), &totalBytesRead);
2195
-
2196
- if (bytesJustRead == sizeof(smplLoopData)) {
2197
- pMetadata->data.smpl.pLoops[iSampleLoop].cuePointId = drwav_bytes_to_u32(smplLoopData + 0);
2198
- pMetadata->data.smpl.pLoops[iSampleLoop].type = drwav_bytes_to_u32(smplLoopData + 4);
2199
- pMetadata->data.smpl.pLoops[iSampleLoop].firstSampleByteOffset = drwav_bytes_to_u32(smplLoopData + 8);
2200
- pMetadata->data.smpl.pLoops[iSampleLoop].lastSampleByteOffset = drwav_bytes_to_u32(smplLoopData + 12);
2201
- pMetadata->data.smpl.pLoops[iSampleLoop].sampleFraction = drwav_bytes_to_u32(smplLoopData + 16);
2202
- pMetadata->data.smpl.pLoops[iSampleLoop].playCount = drwav_bytes_to_u32(smplLoopData + 20);
2203
- } else {
2204
- break;
2192
+
2193
+ /*
2194
+ The loop count needs to be validated against the size of the chunk for safety so we don't
2195
+ attempt to read over the boundary of the chunk.
2196
+ */
2197
+ if (pMetadata->data.smpl.sampleLoopCount == (pChunkHeader->sizeInBytes - DRWAV_SMPL_BYTES) / DRWAV_SMPL_LOOP_BYTES) {
2198
+ pMetadata->data.smpl.pLoops = (drwav_smpl_loop*)drwav__metadata_get_memory(pParser, sizeof(drwav_smpl_loop) * pMetadata->data.smpl.sampleLoopCount, DRWAV_METADATA_ALIGNMENT);
2199
+
2200
+ for (iSampleLoop = 0; iSampleLoop < pMetadata->data.smpl.sampleLoopCount; ++iSampleLoop) {
2201
+ drwav_uint8 smplLoopData[DRWAV_SMPL_LOOP_BYTES];
2202
+ bytesJustRead = drwav__metadata_parser_read(pParser, smplLoopData, sizeof(smplLoopData), &totalBytesRead);
2203
+
2204
+ if (bytesJustRead == sizeof(smplLoopData)) {
2205
+ pMetadata->data.smpl.pLoops[iSampleLoop].cuePointId = drwav_bytes_to_u32(smplLoopData + 0);
2206
+ pMetadata->data.smpl.pLoops[iSampleLoop].type = drwav_bytes_to_u32(smplLoopData + 4);
2207
+ pMetadata->data.smpl.pLoops[iSampleLoop].firstSampleByteOffset = drwav_bytes_to_u32(smplLoopData + 8);
2208
+ pMetadata->data.smpl.pLoops[iSampleLoop].lastSampleByteOffset = drwav_bytes_to_u32(smplLoopData + 12);
2209
+ pMetadata->data.smpl.pLoops[iSampleLoop].sampleFraction = drwav_bytes_to_u32(smplLoopData + 16);
2210
+ pMetadata->data.smpl.pLoops[iSampleLoop].playCount = drwav_bytes_to_u32(smplLoopData + 20);
2211
+ } else {
2212
+ break;
2213
+ }
2205
2214
  }
2206
- }
2207
2215
 
2208
- if (pMetadata->data.smpl.samplerSpecificDataSizeInBytes > 0) {
2209
- pMetadata->data.smpl.pSamplerSpecificData = drwav__metadata_get_memory(pParser, pMetadata->data.smpl.samplerSpecificDataSizeInBytes, 1);
2210
- DRWAV_ASSERT(pMetadata->data.smpl.pSamplerSpecificData != NULL);
2216
+ if (pMetadata->data.smpl.samplerSpecificDataSizeInBytes > 0) {
2217
+ pMetadata->data.smpl.pSamplerSpecificData = drwav__metadata_get_memory(pParser, pMetadata->data.smpl.samplerSpecificDataSizeInBytes, 1);
2218
+ DRWAV_ASSERT(pMetadata->data.smpl.pSamplerSpecificData != NULL);
2211
2219
 
2212
- drwav__metadata_parser_read(pParser, pMetadata->data.smpl.pSamplerSpecificData, pMetadata->data.smpl.samplerSpecificDataSizeInBytes, &totalBytesRead);
2220
+ drwav__metadata_parser_read(pParser, pMetadata->data.smpl.pSamplerSpecificData, pMetadata->data.smpl.samplerSpecificDataSizeInBytes, &totalBytesRead);
2221
+ }
2213
2222
  }
2214
2223
  }
2215
2224
 
2216
2225
  return totalBytesRead;
2217
2226
  }
2218
2227
 
2219
- DRWAV_PRIVATE drwav_uint64 drwav__read_cue_to_metadata_obj(drwav__metadata_parser* pParser, drwav_metadata* pMetadata)
2228
+ DRWAV_PRIVATE drwav_uint64 drwav__read_cue_to_metadata_obj(drwav__metadata_parser* pParser, const drwav_chunk_header* pChunkHeader, drwav_metadata* pMetadata)
2220
2229
  {
2221
2230
  drwav_uint8 cueHeaderSectionData[DRWAV_CUE_BYTES];
2222
2231
  drwav_uint64 totalBytesRead = 0;
@@ -2227,28 +2236,35 @@ DRWAV_PRIVATE drwav_uint64 drwav__read_cue_to_metadata_obj(drwav__metadata_parse
2227
2236
  if (bytesJustRead == sizeof(cueHeaderSectionData)) {
2228
2237
  pMetadata->type = drwav_metadata_type_cue;
2229
2238
  pMetadata->data.cue.cuePointCount = drwav_bytes_to_u32(cueHeaderSectionData);
2230
- pMetadata->data.cue.pCuePoints = (drwav_cue_point*)drwav__metadata_get_memory(pParser, sizeof(drwav_cue_point) * pMetadata->data.cue.cuePointCount, DRWAV_METADATA_ALIGNMENT);
2231
- DRWAV_ASSERT(pMetadata->data.cue.pCuePoints != NULL);
2232
-
2233
- if (pMetadata->data.cue.cuePointCount > 0) {
2234
- drwav_uint32 iCuePoint;
2235
-
2236
- for (iCuePoint = 0; iCuePoint < pMetadata->data.cue.cuePointCount; ++iCuePoint) {
2237
- drwav_uint8 cuePointData[DRWAV_CUE_POINT_BYTES];
2238
- bytesJustRead = drwav__metadata_parser_read(pParser, cuePointData, sizeof(cuePointData), &totalBytesRead);
2239
-
2240
- if (bytesJustRead == sizeof(cuePointData)) {
2241
- pMetadata->data.cue.pCuePoints[iCuePoint].id = drwav_bytes_to_u32(cuePointData + 0);
2242
- pMetadata->data.cue.pCuePoints[iCuePoint].playOrderPosition = drwav_bytes_to_u32(cuePointData + 4);
2243
- pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[0] = cuePointData[8];
2244
- pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[1] = cuePointData[9];
2245
- pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[2] = cuePointData[10];
2246
- pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[3] = cuePointData[11];
2247
- pMetadata->data.cue.pCuePoints[iCuePoint].chunkStart = drwav_bytes_to_u32(cuePointData + 12);
2248
- pMetadata->data.cue.pCuePoints[iCuePoint].blockStart = drwav_bytes_to_u32(cuePointData + 16);
2249
- pMetadata->data.cue.pCuePoints[iCuePoint].sampleByteOffset = drwav_bytes_to_u32(cuePointData + 20);
2250
- } else {
2251
- break;
2239
+
2240
+ /*
2241
+ We need to validate the cue point count against the size of the chunk so we don't read
2242
+ beyond the chunk.
2243
+ */
2244
+ if (pMetadata->data.cue.cuePointCount == (pChunkHeader->sizeInBytes - DRWAV_CUE_BYTES) / DRWAV_CUE_POINT_BYTES) {
2245
+ pMetadata->data.cue.pCuePoints = (drwav_cue_point*)drwav__metadata_get_memory(pParser, sizeof(drwav_cue_point) * pMetadata->data.cue.cuePointCount, DRWAV_METADATA_ALIGNMENT);
2246
+ DRWAV_ASSERT(pMetadata->data.cue.pCuePoints != NULL);
2247
+
2248
+ if (pMetadata->data.cue.cuePointCount > 0) {
2249
+ drwav_uint32 iCuePoint;
2250
+
2251
+ for (iCuePoint = 0; iCuePoint < pMetadata->data.cue.cuePointCount; ++iCuePoint) {
2252
+ drwav_uint8 cuePointData[DRWAV_CUE_POINT_BYTES];
2253
+ bytesJustRead = drwav__metadata_parser_read(pParser, cuePointData, sizeof(cuePointData), &totalBytesRead);
2254
+
2255
+ if (bytesJustRead == sizeof(cuePointData)) {
2256
+ pMetadata->data.cue.pCuePoints[iCuePoint].id = drwav_bytes_to_u32(cuePointData + 0);
2257
+ pMetadata->data.cue.pCuePoints[iCuePoint].playOrderPosition = drwav_bytes_to_u32(cuePointData + 4);
2258
+ pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[0] = cuePointData[8];
2259
+ pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[1] = cuePointData[9];
2260
+ pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[2] = cuePointData[10];
2261
+ pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[3] = cuePointData[11];
2262
+ pMetadata->data.cue.pCuePoints[iCuePoint].chunkStart = drwav_bytes_to_u32(cuePointData + 12);
2263
+ pMetadata->data.cue.pCuePoints[iCuePoint].blockStart = drwav_bytes_to_u32(cuePointData + 16);
2264
+ pMetadata->data.cue.pCuePoints[iCuePoint].sampleByteOffset = drwav_bytes_to_u32(cuePointData + 20);
2265
+ } else {
2266
+ break;
2267
+ }
2252
2268
  }
2253
2269
  }
2254
2270
  }
@@ -2300,7 +2316,7 @@ DRWAV_PRIVATE drwav_uint64 drwav__read_acid_to_metadata_obj(drwav__metadata_pars
2300
2316
  return bytesRead;
2301
2317
  }
2302
2318
 
2303
- DRWAV_PRIVATE size_t drwav__strlen_clamped(char* str, size_t maxToRead)
2319
+ DRWAV_PRIVATE size_t drwav__strlen_clamped(const char* str, size_t maxToRead)
2304
2320
  {
2305
2321
  size_t result = 0;
2306
2322
 
@@ -2311,7 +2327,7 @@ DRWAV_PRIVATE size_t drwav__strlen_clamped(char* str, size_t maxToRead)
2311
2327
  return result;
2312
2328
  }
2313
2329
 
2314
- DRWAV_PRIVATE char* drwav__metadata_copy_string(drwav__metadata_parser* pParser, char* str, size_t maxToRead)
2330
+ DRWAV_PRIVATE char* drwav__metadata_copy_string(drwav__metadata_parser* pParser, const char* str, size_t maxToRead)
2315
2331
  {
2316
2332
  size_t len = drwav__strlen_clamped(str, maxToRead);
2317
2333
 
@@ -2328,77 +2344,183 @@ DRWAV_PRIVATE char* drwav__metadata_copy_string(drwav__metadata_parser* pParser,
2328
2344
  }
2329
2345
  }
2330
2346
 
2347
+ typedef struct
2348
+ {
2349
+ const void* pBuffer;
2350
+ size_t sizeInBytes;
2351
+ size_t cursor;
2352
+ } drwav_buffer_reader;
2353
+
2354
+ DRWAV_PRIVATE drwav_result drwav_buffer_reader_init(const void* pBuffer, size_t sizeInBytes, drwav_buffer_reader* pReader)
2355
+ {
2356
+ DRWAV_ASSERT(pBuffer != NULL);
2357
+ DRWAV_ASSERT(pReader != NULL);
2358
+
2359
+ DRWAV_ZERO_OBJECT(pReader);
2360
+
2361
+ pReader->pBuffer = pBuffer;
2362
+ pReader->sizeInBytes = sizeInBytes;
2363
+ pReader->cursor = 0;
2364
+
2365
+ return DRWAV_SUCCESS;
2366
+ }
2367
+
2368
+ DRWAV_PRIVATE const void* drwav_buffer_reader_ptr(const drwav_buffer_reader* pReader)
2369
+ {
2370
+ DRWAV_ASSERT(pReader != NULL);
2371
+
2372
+ return drwav_offset_ptr(pReader->pBuffer, pReader->cursor);
2373
+ }
2374
+
2375
+ DRWAV_PRIVATE drwav_result drwav_buffer_reader_seek(drwav_buffer_reader* pReader, size_t bytesToSeek)
2376
+ {
2377
+ DRWAV_ASSERT(pReader != NULL);
2378
+
2379
+ if (pReader->cursor + bytesToSeek > pReader->sizeInBytes) {
2380
+ return DRWAV_BAD_SEEK; /* Seeking too far forward. */
2381
+ }
2382
+
2383
+ pReader->cursor += bytesToSeek;
2384
+
2385
+ return DRWAV_SUCCESS;
2386
+ }
2387
+
2388
+ DRWAV_PRIVATE drwav_result drwav_buffer_reader_read(drwav_buffer_reader* pReader, void* pDst, size_t bytesToRead, size_t* pBytesRead)
2389
+ {
2390
+ drwav_result result = DRWAV_SUCCESS;
2391
+ size_t bytesRemaining;
2392
+
2393
+ DRWAV_ASSERT(pReader != NULL);
2394
+
2395
+ if (pBytesRead != NULL) {
2396
+ *pBytesRead = 0;
2397
+ }
2398
+
2399
+ bytesRemaining = (pReader->sizeInBytes - pReader->cursor);
2400
+ if (bytesToRead > bytesRemaining) {
2401
+ bytesToRead = bytesRemaining;
2402
+ }
2403
+
2404
+ if (pDst == NULL) {
2405
+ /* Seek. */
2406
+ result = drwav_buffer_reader_seek(pReader, bytesToRead);
2407
+ } else {
2408
+ /* Read. */
2409
+ DRWAV_COPY_MEMORY(pDst, drwav_buffer_reader_ptr(pReader), bytesToRead);
2410
+ pReader->cursor += bytesToRead;
2411
+ }
2412
+
2413
+ DRWAV_ASSERT(pReader->cursor <= pReader->sizeInBytes);
2414
+
2415
+ if (result == DRWAV_SUCCESS) {
2416
+ if (pBytesRead != NULL) {
2417
+ *pBytesRead = bytesToRead;
2418
+ }
2419
+ }
2420
+
2421
+ return DRWAV_SUCCESS;
2422
+ }
2423
+
2424
+ DRWAV_PRIVATE drwav_result drwav_buffer_reader_read_u16(drwav_buffer_reader* pReader, drwav_uint16* pDst)
2425
+ {
2426
+ drwav_result result;
2427
+ size_t bytesRead;
2428
+ drwav_uint8 data[2];
2429
+
2430
+ DRWAV_ASSERT(pReader != NULL);
2431
+ DRWAV_ASSERT(pDst != NULL);
2432
+
2433
+ *pDst = 0; /* Safety. */
2434
+
2435
+ result = drwav_buffer_reader_read(pReader, data, sizeof(*pDst), &bytesRead);
2436
+ if (result != DRWAV_SUCCESS || bytesRead != sizeof(*pDst)) {
2437
+ return result;
2438
+ }
2439
+
2440
+ *pDst = drwav_bytes_to_u16(data);
2441
+
2442
+ return DRWAV_SUCCESS;
2443
+ }
2444
+
2445
+ DRWAV_PRIVATE drwav_result drwav_buffer_reader_read_u32(drwav_buffer_reader* pReader, drwav_uint32* pDst)
2446
+ {
2447
+ drwav_result result;
2448
+ size_t bytesRead;
2449
+ drwav_uint8 data[4];
2450
+
2451
+ DRWAV_ASSERT(pReader != NULL);
2452
+ DRWAV_ASSERT(pDst != NULL);
2453
+
2454
+ *pDst = 0; /* Safety. */
2455
+
2456
+ result = drwav_buffer_reader_read(pReader, data, sizeof(*pDst), &bytesRead);
2457
+ if (result != DRWAV_SUCCESS || bytesRead != sizeof(*pDst)) {
2458
+ return result;
2459
+ }
2460
+
2461
+ *pDst = drwav_bytes_to_u32(data);
2462
+
2463
+ return DRWAV_SUCCESS;
2464
+ }
2465
+
2466
+
2467
+
2331
2468
  DRWAV_PRIVATE drwav_uint64 drwav__read_bext_to_metadata_obj(drwav__metadata_parser* pParser, drwav_metadata* pMetadata, drwav_uint64 chunkSize)
2332
2469
  {
2333
2470
  drwav_uint8 bextData[DRWAV_BEXT_BYTES];
2334
- drwav_uint64 bytesRead = drwav__metadata_parser_read(pParser, bextData, sizeof(bextData), NULL);
2471
+ size_t bytesRead = drwav__metadata_parser_read(pParser, bextData, sizeof(bextData), NULL);
2335
2472
 
2336
2473
  DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
2337
2474
 
2338
2475
  if (bytesRead == sizeof(bextData)) {
2339
- drwav_uint8* pReadPointer;
2476
+ drwav_buffer_reader reader;
2340
2477
  drwav_uint32 timeReferenceLow;
2341
2478
  drwav_uint32 timeReferenceHigh;
2342
2479
  size_t extraBytes;
2343
2480
 
2344
2481
  pMetadata->type = drwav_metadata_type_bext;
2345
2482
 
2346
- pReadPointer = bextData;
2347
- pMetadata->data.bext.pDescription = drwav__metadata_copy_string(pParser, (char*)(pReadPointer), DRWAV_BEXT_DESCRIPTION_BYTES);
2348
- pReadPointer += DRWAV_BEXT_DESCRIPTION_BYTES;
2349
-
2350
- pMetadata->data.bext.pOriginatorName = drwav__metadata_copy_string(pParser, (char*)(pReadPointer), DRWAV_BEXT_ORIGINATOR_NAME_BYTES);
2351
- pReadPointer += DRWAV_BEXT_ORIGINATOR_NAME_BYTES;
2352
-
2353
- pMetadata->data.bext.pOriginatorReference = drwav__metadata_copy_string(pParser, (char*)(pReadPointer), DRWAV_BEXT_ORIGINATOR_REF_BYTES);
2354
- pReadPointer += DRWAV_BEXT_ORIGINATOR_REF_BYTES;
2483
+ if (drwav_buffer_reader_init(bextData, bytesRead, &reader) == DRWAV_SUCCESS) {
2484
+ pMetadata->data.bext.pDescription = drwav__metadata_copy_string(pParser, (const char*)drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_DESCRIPTION_BYTES);
2485
+ drwav_buffer_reader_seek(&reader, DRWAV_BEXT_DESCRIPTION_BYTES);
2355
2486
 
2356
- memcpy(pMetadata->data.bext.pOriginationDate, pReadPointer, sizeof(pMetadata->data.bext.pOriginationDate));
2357
- pReadPointer += sizeof(pMetadata->data.bext.pOriginationDate);
2487
+ pMetadata->data.bext.pOriginatorName = drwav__metadata_copy_string(pParser, (const char*)drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_ORIGINATOR_NAME_BYTES);
2488
+ drwav_buffer_reader_seek(&reader, DRWAV_BEXT_ORIGINATOR_NAME_BYTES);
2358
2489
 
2359
- memcpy(pMetadata->data.bext.pOriginationTime, pReadPointer, sizeof(pMetadata->data.bext.pOriginationTime));
2360
- pReadPointer += sizeof(pMetadata->data.bext.pOriginationTime);
2490
+ pMetadata->data.bext.pOriginatorReference = drwav__metadata_copy_string(pParser, (const char*)drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_ORIGINATOR_REF_BYTES);
2491
+ drwav_buffer_reader_seek(&reader, DRWAV_BEXT_ORIGINATOR_REF_BYTES);
2361
2492
 
2362
- timeReferenceLow = drwav_bytes_to_u32(pReadPointer);
2363
- pReadPointer += sizeof(drwav_uint32);
2364
- timeReferenceHigh = drwav_bytes_to_u32(pReadPointer);
2365
- pReadPointer += sizeof(drwav_uint32);
2366
- pMetadata->data.bext.timeReference = ((drwav_uint64)timeReferenceHigh << 32) + timeReferenceLow;
2493
+ drwav_buffer_reader_read(&reader, pMetadata->data.bext.pOriginationDate, sizeof(pMetadata->data.bext.pOriginationDate), NULL);
2494
+ drwav_buffer_reader_read(&reader, pMetadata->data.bext.pOriginationTime, sizeof(pMetadata->data.bext.pOriginationTime), NULL);
2367
2495
 
2368
- pMetadata->data.bext.version = drwav_bytes_to_u16(pReadPointer);
2369
- pReadPointer += sizeof(drwav_uint16);
2496
+ drwav_buffer_reader_read_u32(&reader, &timeReferenceLow);
2497
+ drwav_buffer_reader_read_u32(&reader, &timeReferenceHigh);
2498
+ pMetadata->data.bext.timeReference = ((drwav_uint64)timeReferenceHigh << 32) + timeReferenceLow;
2370
2499
 
2371
- pMetadata->data.bext.pUMID = drwav__metadata_get_memory(pParser, DRWAV_BEXT_UMID_BYTES, 1);
2372
- memcpy(pMetadata->data.bext.pUMID, pReadPointer, DRWAV_BEXT_UMID_BYTES);
2373
- pReadPointer += DRWAV_BEXT_UMID_BYTES;
2500
+ drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.version);
2374
2501
 
2375
- pMetadata->data.bext.loudnessValue = drwav_bytes_to_u16(pReadPointer);
2376
- pReadPointer += sizeof(drwav_uint16);
2502
+ pMetadata->data.bext.pUMID = drwav__metadata_get_memory(pParser, DRWAV_BEXT_UMID_BYTES, 1);
2503
+ drwav_buffer_reader_read(&reader, pMetadata->data.bext.pUMID, DRWAV_BEXT_UMID_BYTES, NULL);
2377
2504
 
2378
- pMetadata->data.bext.loudnessRange = drwav_bytes_to_u16(pReadPointer);
2379
- pReadPointer += sizeof(drwav_uint16);
2505
+ drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.loudnessValue);
2506
+ drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.loudnessRange);
2507
+ drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.maxTruePeakLevel);
2508
+ drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.maxMomentaryLoudness);
2509
+ drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.maxShortTermLoudness);
2380
2510
 
2381
- pMetadata->data.bext.maxTruePeakLevel = drwav_bytes_to_u16(pReadPointer);
2382
- pReadPointer += sizeof(drwav_uint16);
2511
+ DRWAV_ASSERT((drwav_offset_ptr(drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_RESERVED_BYTES)) == (bextData + DRWAV_BEXT_BYTES));
2383
2512
 
2384
- pMetadata->data.bext.maxMomentaryLoudness = drwav_bytes_to_u16(pReadPointer);
2385
- pReadPointer += sizeof(drwav_uint16);
2513
+ extraBytes = (size_t)(chunkSize - DRWAV_BEXT_BYTES);
2514
+ if (extraBytes > 0) {
2515
+ pMetadata->data.bext.pCodingHistory = (char*)drwav__metadata_get_memory(pParser, extraBytes + 1, 1);
2516
+ DRWAV_ASSERT(pMetadata->data.bext.pCodingHistory != NULL);
2386
2517
 
2387
- pMetadata->data.bext.maxShortTermLoudness = drwav_bytes_to_u16(pReadPointer);
2388
- pReadPointer += sizeof(drwav_uint16);
2389
-
2390
- DRWAV_ASSERT((pReadPointer + DRWAV_BEXT_RESERVED_BYTES) == (bextData + DRWAV_BEXT_BYTES));
2391
-
2392
- extraBytes = (size_t)(chunkSize - DRWAV_BEXT_BYTES);
2393
- if (extraBytes > 0) {
2394
- pMetadata->data.bext.pCodingHistory = (char*)drwav__metadata_get_memory(pParser, extraBytes + 1, 1);
2395
- DRWAV_ASSERT(pMetadata->data.bext.pCodingHistory != NULL);
2396
-
2397
- bytesRead += drwav__metadata_parser_read(pParser, pMetadata->data.bext.pCodingHistory, extraBytes, NULL);
2398
- pMetadata->data.bext.codingHistorySize = (drwav_uint32)strlen(pMetadata->data.bext.pCodingHistory);
2399
- } else {
2400
- pMetadata->data.bext.pCodingHistory = NULL;
2401
- pMetadata->data.bext.codingHistorySize = 0;
2518
+ bytesRead += drwav__metadata_parser_read(pParser, pMetadata->data.bext.pCodingHistory, extraBytes, NULL);
2519
+ pMetadata->data.bext.codingHistorySize = (drwav_uint32)strlen(pMetadata->data.bext.pCodingHistory);
2520
+ } else {
2521
+ pMetadata->data.bext.pCodingHistory = NULL;
2522
+ pMetadata->data.bext.codingHistorySize = 0;
2523
+ }
2402
2524
  }
2403
2525
  }
2404
2526
 
@@ -2568,18 +2690,25 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_chunk(drwav__metadata_parser*
2568
2690
  bytesJustRead = drwav__metadata_parser_read(pParser, buffer, sizeof(buffer), &bytesRead);
2569
2691
  if (bytesJustRead == sizeof(buffer)) {
2570
2692
  drwav_uint32 loopCount = drwav_bytes_to_u32(buffer);
2571
-
2572
- bytesJustRead = drwav__metadata_parser_read(pParser, buffer, sizeof(buffer), &bytesRead);
2573
- if (bytesJustRead == sizeof(buffer)) {
2574
- drwav_uint32 samplerSpecificDataSizeInBytes = drwav_bytes_to_u32(buffer);
2575
-
2576
- pParser->metadataCount += 1;
2577
- drwav__metadata_request_extra_memory_for_stage_2(pParser, sizeof(drwav_smpl_loop) * loopCount, DRWAV_METADATA_ALIGNMENT);
2578
- drwav__metadata_request_extra_memory_for_stage_2(pParser, samplerSpecificDataSizeInBytes, 1);
2579
- }
2693
+ drwav_uint64 calculatedLoopCount;
2694
+
2695
+ /* The loop count must be validated against the size of the chunk. */
2696
+ calculatedLoopCount = (pChunkHeader->sizeInBytes - DRWAV_SMPL_BYTES) / DRWAV_SMPL_LOOP_BYTES;
2697
+ if (calculatedLoopCount == loopCount) {
2698
+ bytesJustRead = drwav__metadata_parser_read(pParser, buffer, sizeof(buffer), &bytesRead);
2699
+ if (bytesJustRead == sizeof(buffer)) {
2700
+ drwav_uint32 samplerSpecificDataSizeInBytes = drwav_bytes_to_u32(buffer);
2701
+
2702
+ pParser->metadataCount += 1;
2703
+ drwav__metadata_request_extra_memory_for_stage_2(pParser, sizeof(drwav_smpl_loop) * loopCount, DRWAV_METADATA_ALIGNMENT);
2704
+ drwav__metadata_request_extra_memory_for_stage_2(pParser, samplerSpecificDataSizeInBytes, 1);
2705
+ }
2706
+ } else {
2707
+ /* Loop count in header does not match the size of the chunk. */
2708
+ }
2580
2709
  }
2581
2710
  } else {
2582
- bytesRead = drwav__read_smpl_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor]);
2711
+ bytesRead = drwav__read_smpl_to_metadata_obj(pParser, pChunkHeader, &pParser->pMetadata[pParser->metadataCursor]);
2583
2712
  if (bytesRead == pChunkHeader->sizeInBytes) {
2584
2713
  pParser->metadataCursor += 1;
2585
2714
  } else {
@@ -2628,7 +2757,7 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_chunk(drwav__metadata_parser*
2628
2757
  cueCount = (size_t)(pChunkHeader->sizeInBytes - DRWAV_CUE_BYTES) / DRWAV_CUE_POINT_BYTES;
2629
2758
  drwav__metadata_request_extra_memory_for_stage_2(pParser, sizeof(drwav_cue_point) * cueCount, DRWAV_METADATA_ALIGNMENT);
2630
2759
  } else {
2631
- bytesRead = drwav__read_cue_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor]);
2760
+ bytesRead = drwav__read_cue_to_metadata_obj(pParser, pChunkHeader, &pParser->pMetadata[pParser->metadataCursor]);
2632
2761
  if (bytesRead == pChunkHeader->sizeInBytes) {
2633
2762
  pParser->metadataCursor += 1;
2634
2763
  } else {
@@ -3222,7 +3351,12 @@ DRWAV_PRIVATE drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc on
3222
3351
  if (sampleCountFromFactChunk != 0) {
3223
3352
  pWav->totalPCMFrameCount = sampleCountFromFactChunk;
3224
3353
  } else {
3225
- pWav->totalPCMFrameCount = dataChunkSize / drwav_get_bytes_per_pcm_frame(pWav);
3354
+ drwav_uint32 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
3355
+ if (bytesPerFrame == 0) {
3356
+ return DRWAV_FALSE; /* Invalid file. */
3357
+ }
3358
+
3359
+ pWav->totalPCMFrameCount = dataChunkSize / bytesPerFrame;
3226
3360
 
3227
3361
  if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM) {
3228
3362
  drwav_uint64 totalBlockHeaderSizeInBytes;
@@ -5135,6 +5269,7 @@ DRWAV_API drwav_result drwav_uninit(drwav* pWav)
5135
5269
  DRWAV_API size_t drwav_read_raw(drwav* pWav, size_t bytesToRead, void* pBufferOut)
5136
5270
  {
5137
5271
  size_t bytesRead;
5272
+ drwav_uint32 bytesPerFrame;
5138
5273
 
5139
5274
  if (pWav == NULL || bytesToRead == 0) {
5140
5275
  return 0; /* Invalid args. */
@@ -5148,6 +5283,11 @@ DRWAV_API size_t drwav_read_raw(drwav* pWav, size_t bytesToRead, void* pBufferOu
5148
5283
  return 0; /* At end. */
5149
5284
  }
5150
5285
 
5286
+ bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
5287
+ if (bytesPerFrame == 0) {
5288
+ return 0; /* Could not determine the bytes per frame. */
5289
+ }
5290
+
5151
5291
  if (pBufferOut != NULL) {
5152
5292
  bytesRead = pWav->onRead(pWav->pUserData, pBufferOut, bytesToRead);
5153
5293
  } else {
@@ -5184,7 +5324,7 @@ DRWAV_API size_t drwav_read_raw(drwav* pWav, size_t bytesToRead, void* pBufferOu
5184
5324
  }
5185
5325
  }
5186
5326
 
5187
- pWav->readCursorInPCMFrames += bytesRead / drwav_get_bytes_per_pcm_frame(pWav);
5327
+ pWav->readCursorInPCMFrames += bytesRead / bytesPerFrame;
5188
5328
 
5189
5329
  pWav->bytesRemaining -= bytesRead;
5190
5330
  return bytesRead;
@@ -5233,7 +5373,12 @@ DRWAV_API drwav_uint64 drwav_read_pcm_frames_be(drwav* pWav, drwav_uint64 frames
5233
5373
  drwav_uint64 framesRead = drwav_read_pcm_frames_le(pWav, framesToRead, pBufferOut);
5234
5374
 
5235
5375
  if (pBufferOut != NULL) {
5236
- drwav__bswap_samples(pBufferOut, framesRead*pWav->channels, drwav_get_bytes_per_pcm_frame(pWav)/pWav->channels, pWav->translatedFormatTag);
5376
+ drwav_uint32 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
5377
+ if (bytesPerFrame == 0) {
5378
+ return 0; /* Could not get the bytes per frame which means bytes per sample cannot be determined and we don't know how to byte swap. */
5379
+ }
5380
+
5381
+ drwav__bswap_samples(pBufferOut, framesRead*pWav->channels, bytesPerFrame/pWav->channels, pWav->translatedFormatTag);
5237
5382
  }
5238
5383
 
5239
5384
  return framesRead;
@@ -5348,12 +5493,18 @@ DRWAV_API drwav_bool32 drwav_seek_to_pcm_frame(drwav* pWav, drwav_uint64 targetF
5348
5493
  drwav_uint64 currentBytePos;
5349
5494
  drwav_uint64 targetBytePos;
5350
5495
  drwav_uint64 offset;
5496
+ drwav_uint32 bytesPerFrame;
5351
5497
 
5352
- totalSizeInBytes = pWav->totalPCMFrameCount * drwav_get_bytes_per_pcm_frame(pWav);
5498
+ bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
5499
+ if (bytesPerFrame == 0) {
5500
+ return DRWAV_FALSE; /* Not able to calculate offset. */
5501
+ }
5502
+
5503
+ totalSizeInBytes = pWav->totalPCMFrameCount * bytesPerFrame;
5353
5504
  DRWAV_ASSERT(totalSizeInBytes >= pWav->bytesRemaining);
5354
5505
 
5355
5506
  currentBytePos = totalSizeInBytes - pWav->bytesRemaining;
5356
- targetBytePos = targetFrameIndex * drwav_get_bytes_per_pcm_frame(pWav);
5507
+ targetBytePos = targetFrameIndex * bytesPerFrame;
5357
5508
 
5358
5509
  if (currentBytePos < targetBytePos) {
5359
5510
  /* Offset forwards. */
@@ -5372,7 +5523,7 @@ DRWAV_API drwav_bool32 drwav_seek_to_pcm_frame(drwav* pWav, drwav_uint64 targetF
5372
5523
  return DRWAV_FALSE;
5373
5524
  }
5374
5525
 
5375
- pWav->readCursorInPCMFrames += offset32 / drwav_get_bytes_per_pcm_frame(pWav);
5526
+ pWav->readCursorInPCMFrames += offset32 / bytesPerFrame;
5376
5527
  pWav->bytesRemaining -= offset32;
5377
5528
  offset -= offset32;
5378
5529
  }
@@ -5488,6 +5639,9 @@ DRWAV_API drwav_uint64 drwav_write_pcm_frames_be(drwav* pWav, drwav_uint64 frame
5488
5639
  pRunningData = (const drwav_uint8*)pData;
5489
5640
 
5490
5641
  bytesPerSample = drwav_get_bytes_per_pcm_frame(pWav) / pWav->channels;
5642
+ if (bytesPerSample == 0) {
5643
+ return 0; /* Cannot determine bytes per sample, or bytes per sample is less than one byte. */
5644
+ }
5491
5645
 
5492
5646
  while (bytesToWrite > 0) {
5493
5647
  drwav_uint8 temp[4096];
@@ -5763,7 +5917,7 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uin
5763
5917
  }
5764
5918
 
5765
5919
  pWav->ima.predictor[0] = drwav_bytes_to_s16(header + 0);
5766
- pWav->ima.stepIndex[0] = header[2];
5920
+ pWav->ima.stepIndex[0] = drwav_clamp(header[2], 0, (drwav_int32)drwav_countof(stepTable)-1); /* Clamp not necessary because we checked above, but adding here to silence a static analysis warning. */
5767
5921
  pWav->ima.cachedFrames[drwav_countof(pWav->ima.cachedFrames) - 1] = pWav->ima.predictor[0];
5768
5922
  pWav->ima.cachedFrameCount = 1;
5769
5923
  } else {
@@ -5781,9 +5935,9 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uin
5781
5935
  }
5782
5936
 
5783
5937
  pWav->ima.predictor[0] = drwav_bytes_to_s16(header + 0);
5784
- pWav->ima.stepIndex[0] = header[2];
5938
+ pWav->ima.stepIndex[0] = drwav_clamp(header[2], 0, (drwav_int32)drwav_countof(stepTable)-1); /* Clamp not necessary because we checked above, but adding here to silence a static analysis warning. */
5785
5939
  pWav->ima.predictor[1] = drwav_bytes_to_s16(header + 4);
5786
- pWav->ima.stepIndex[1] = header[6];
5940
+ pWav->ima.stepIndex[1] = drwav_clamp(header[6], 0, (drwav_int32)drwav_countof(stepTable)-1); /* Clamp not necessary because we checked above, but adding here to silence a static analysis warning. */
5787
5941
 
5788
5942
  pWav->ima.cachedFrames[drwav_countof(pWav->ima.cachedFrames) - 2] = pWav->ima.predictor[0];
5789
5943
  pWav->ima.cachedFrames[drwav_countof(pWav->ima.cachedFrames) - 1] = pWav->ima.predictor[1];
@@ -5928,7 +6082,7 @@ static DRWAV_INLINE drwav_int16 drwav__mulaw_to_s16(drwav_uint8 sampleIn)
5928
6082
 
5929
6083
  DRWAV_PRIVATE void drwav__pcm_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample)
5930
6084
  {
5931
- unsigned int i;
6085
+ size_t i;
5932
6086
 
5933
6087
  /* Special case for 8-bit sample data because it's treated as unsigned. */
5934
6088
  if (bytesPerSample == 1) {
@@ -5996,8 +6150,10 @@ DRWAV_PRIVATE void drwav__ieee_to_s16(drwav_int16* pOut, const drwav_uint8* pIn,
5996
6150
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__pcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
5997
6151
  {
5998
6152
  drwav_uint64 totalFramesRead;
5999
- drwav_uint8 sampleData[4096];
6153
+ drwav_uint8 sampleData[4096] = {0};
6000
6154
  drwav_uint32 bytesPerFrame;
6155
+ drwav_uint32 bytesPerSample;
6156
+ drwav_uint64 samplesRead;
6001
6157
 
6002
6158
  /* Fast path. */
6003
6159
  if ((pWav->translatedFormatTag == DR_WAVE_FORMAT_PCM && pWav->bitsPerSample == 16) || pBufferOut == NULL) {
@@ -6009,6 +6165,11 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__pcm(drwav* pWav, drwav_uin
6009
6165
  return 0;
6010
6166
  }
6011
6167
 
6168
+ bytesPerSample = bytesPerFrame / pWav->channels;
6169
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
6170
+ return 0; /* Only byte-aligned formats are supported. */
6171
+ }
6172
+
6012
6173
  totalFramesRead = 0;
6013
6174
 
6014
6175
  while (framesToRead > 0) {
@@ -6020,9 +6181,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__pcm(drwav* pWav, drwav_uin
6020
6181
 
6021
6182
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6022
6183
 
6023
- drwav__pcm_to_s16(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels), bytesPerFrame/pWav->channels);
6184
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
6185
+ samplesRead = framesRead * pWav->channels;
6186
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
6187
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
6188
+ break;
6189
+ }
6024
6190
 
6025
- pBufferOut += framesRead*pWav->channels;
6191
+ drwav__pcm_to_s16(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
6192
+
6193
+ pBufferOut += samplesRead;
6026
6194
  framesToRead -= framesRead;
6027
6195
  totalFramesRead += framesRead;
6028
6196
  }
@@ -6033,8 +6201,10 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__pcm(drwav* pWav, drwav_uin
6033
6201
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ieee(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
6034
6202
  {
6035
6203
  drwav_uint64 totalFramesRead;
6036
- drwav_uint8 sampleData[4096];
6204
+ drwav_uint8 sampleData[4096] = {0};
6037
6205
  drwav_uint32 bytesPerFrame;
6206
+ drwav_uint32 bytesPerSample;
6207
+ drwav_uint64 samplesRead;
6038
6208
 
6039
6209
  if (pBufferOut == NULL) {
6040
6210
  return drwav_read_pcm_frames(pWav, framesToRead, NULL);
@@ -6045,6 +6215,11 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ieee(drwav* pWav, drwav_ui
6045
6215
  return 0;
6046
6216
  }
6047
6217
 
6218
+ bytesPerSample = bytesPerFrame / pWav->channels;
6219
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
6220
+ return 0; /* Only byte-aligned formats are supported. */
6221
+ }
6222
+
6048
6223
  totalFramesRead = 0;
6049
6224
 
6050
6225
  while (framesToRead > 0) {
@@ -6056,9 +6231,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ieee(drwav* pWav, drwav_ui
6056
6231
 
6057
6232
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6058
6233
 
6059
- drwav__ieee_to_s16(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels), bytesPerFrame/pWav->channels);
6234
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
6235
+ samplesRead = framesRead * pWav->channels;
6236
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
6237
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
6238
+ break;
6239
+ }
6240
+
6241
+ drwav__ieee_to_s16(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample); /* Safe cast. */
6060
6242
 
6061
- pBufferOut += framesRead*pWav->channels;
6243
+ pBufferOut += samplesRead;
6062
6244
  framesToRead -= framesRead;
6063
6245
  totalFramesRead += framesRead;
6064
6246
  }
@@ -6069,8 +6251,10 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ieee(drwav* pWav, drwav_ui
6069
6251
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__alaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
6070
6252
  {
6071
6253
  drwav_uint64 totalFramesRead;
6072
- drwav_uint8 sampleData[4096];
6254
+ drwav_uint8 sampleData[4096] = {0};
6073
6255
  drwav_uint32 bytesPerFrame;
6256
+ drwav_uint32 bytesPerSample;
6257
+ drwav_uint64 samplesRead;
6074
6258
 
6075
6259
  if (pBufferOut == NULL) {
6076
6260
  return drwav_read_pcm_frames(pWav, framesToRead, NULL);
@@ -6081,6 +6265,11 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__alaw(drwav* pWav, drwav_ui
6081
6265
  return 0;
6082
6266
  }
6083
6267
 
6268
+ bytesPerSample = bytesPerFrame / pWav->channels;
6269
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
6270
+ return 0; /* Only byte-aligned formats are supported. */
6271
+ }
6272
+
6084
6273
  totalFramesRead = 0;
6085
6274
 
6086
6275
  while (framesToRead > 0) {
@@ -6092,9 +6281,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__alaw(drwav* pWav, drwav_ui
6092
6281
 
6093
6282
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6094
6283
 
6095
- drwav_alaw_to_s16(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels));
6284
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
6285
+ samplesRead = framesRead * pWav->channels;
6286
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
6287
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
6288
+ break;
6289
+ }
6096
6290
 
6097
- pBufferOut += framesRead*pWav->channels;
6291
+ drwav_alaw_to_s16(pBufferOut, sampleData, (size_t)samplesRead);
6292
+
6293
+ pBufferOut += samplesRead;
6098
6294
  framesToRead -= framesRead;
6099
6295
  totalFramesRead += framesRead;
6100
6296
  }
@@ -6105,8 +6301,10 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__alaw(drwav* pWav, drwav_ui
6105
6301
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__mulaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
6106
6302
  {
6107
6303
  drwav_uint64 totalFramesRead;
6108
- drwav_uint8 sampleData[4096];
6304
+ drwav_uint8 sampleData[4096] = {0};
6109
6305
  drwav_uint32 bytesPerFrame;
6306
+ drwav_uint32 bytesPerSample;
6307
+ drwav_uint64 samplesRead;
6110
6308
 
6111
6309
  if (pBufferOut == NULL) {
6112
6310
  return drwav_read_pcm_frames(pWav, framesToRead, NULL);
@@ -6117,6 +6315,11 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__mulaw(drwav* pWav, drwav_u
6117
6315
  return 0;
6118
6316
  }
6119
6317
 
6318
+ bytesPerSample = bytesPerFrame / pWav->channels;
6319
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
6320
+ return 0; /* Only byte-aligned formats are supported. */
6321
+ }
6322
+
6120
6323
  totalFramesRead = 0;
6121
6324
 
6122
6325
  while (framesToRead > 0) {
@@ -6128,9 +6331,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__mulaw(drwav* pWav, drwav_u
6128
6331
 
6129
6332
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6130
6333
 
6131
- drwav_mulaw_to_s16(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels));
6334
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
6335
+ samplesRead = framesRead * pWav->channels;
6336
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
6337
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
6338
+ break;
6339
+ }
6132
6340
 
6133
- pBufferOut += framesRead*pWav->channels;
6341
+ drwav_mulaw_to_s16(pBufferOut, sampleData, (size_t)samplesRead);
6342
+
6343
+ pBufferOut += samplesRead;
6134
6344
  framesToRead -= framesRead;
6135
6345
  totalFramesRead += framesRead;
6136
6346
  }
@@ -6354,14 +6564,21 @@ DRWAV_PRIVATE void drwav__ieee_to_f32(float* pOut, const drwav_uint8* pIn, size_
6354
6564
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__pcm(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
6355
6565
  {
6356
6566
  drwav_uint64 totalFramesRead;
6357
- drwav_uint8 sampleData[4096];
6567
+ drwav_uint8 sampleData[4096] = {0};
6358
6568
  drwav_uint32 bytesPerFrame;
6569
+ drwav_uint32 bytesPerSample;
6570
+ drwav_uint64 samplesRead;
6359
6571
 
6360
6572
  bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6361
6573
  if (bytesPerFrame == 0) {
6362
6574
  return 0;
6363
6575
  }
6364
6576
 
6577
+ bytesPerSample = bytesPerFrame / pWav->channels;
6578
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
6579
+ return 0; /* Only byte-aligned formats are supported. */
6580
+ }
6581
+
6365
6582
  totalFramesRead = 0;
6366
6583
 
6367
6584
  while (framesToRead > 0) {
@@ -6373,39 +6590,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__pcm(drwav* pWav, drwav_uin
6373
6590
 
6374
6591
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6375
6592
 
6376
- drwav__pcm_to_f32(pBufferOut, sampleData, (size_t)framesRead*pWav->channels, bytesPerFrame/pWav->channels);
6377
-
6378
- pBufferOut += framesRead*pWav->channels;
6379
- framesToRead -= framesRead;
6380
- totalFramesRead += framesRead;
6381
- }
6382
-
6383
- return totalFramesRead;
6384
- }
6385
-
6386
- DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__msadpcm(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
6387
- {
6388
- /*
6389
- We're just going to borrow the implementation from the drwav_read_s16() since ADPCM is a little bit more complicated than other formats and I don't
6390
- want to duplicate that code.
6391
- */
6392
- drwav_uint64 totalFramesRead;
6393
- drwav_int16 samples16[2048];
6394
-
6395
- totalFramesRead = 0;
6396
-
6397
- while (framesToRead > 0) {
6398
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, drwav_countof(samples16)/pWav->channels);
6399
- drwav_uint64 framesRead = drwav_read_pcm_frames_s16(pWav, framesToReadThisIteration, samples16);
6400
- if (framesRead == 0) {
6593
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
6594
+ samplesRead = framesRead * pWav->channels;
6595
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
6596
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
6401
6597
  break;
6402
6598
  }
6403
6599
 
6404
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6405
-
6406
- drwav_s16_to_f32(pBufferOut, samples16, (size_t)(framesRead*pWav->channels)); /* <-- Safe cast because we're clamping to 2048. */
6600
+ drwav__pcm_to_f32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
6407
6601
 
6408
- pBufferOut += framesRead*pWav->channels;
6602
+ pBufferOut += samplesRead;
6409
6603
  framesToRead -= framesRead;
6410
6604
  totalFramesRead += framesRead;
6411
6605
  }
@@ -6413,10 +6607,10 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__msadpcm(drwav* pWav, drwav
6413
6607
  return totalFramesRead;
6414
6608
  }
6415
6609
 
6416
- DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__ima(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
6610
+ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__msadpcm_ima(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
6417
6611
  {
6418
6612
  /*
6419
- We're just going to borrow the implementation from the drwav_read_s16() since IMA-ADPCM is a little bit more complicated than other formats and I don't
6613
+ We're just going to borrow the implementation from the drwav_read_s16() since ADPCM is a little bit more complicated than other formats and I don't
6420
6614
  want to duplicate that code.
6421
6615
  */
6422
6616
  drwav_uint64 totalFramesRead;
@@ -6446,8 +6640,10 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__ima(drwav* pWav, drwav_uin
6446
6640
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__ieee(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
6447
6641
  {
6448
6642
  drwav_uint64 totalFramesRead;
6449
- drwav_uint8 sampleData[4096];
6643
+ drwav_uint8 sampleData[4096] = {0};
6450
6644
  drwav_uint32 bytesPerFrame;
6645
+ drwav_uint32 bytesPerSample;
6646
+ drwav_uint64 samplesRead;
6451
6647
 
6452
6648
  /* Fast path. */
6453
6649
  if (pWav->translatedFormatTag == DR_WAVE_FORMAT_IEEE_FLOAT && pWav->bitsPerSample == 32) {
@@ -6459,6 +6655,11 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__ieee(drwav* pWav, drwav_ui
6459
6655
  return 0;
6460
6656
  }
6461
6657
 
6658
+ bytesPerSample = bytesPerFrame / pWav->channels;
6659
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
6660
+ return 0; /* Only byte-aligned formats are supported. */
6661
+ }
6662
+
6462
6663
  totalFramesRead = 0;
6463
6664
 
6464
6665
  while (framesToRead > 0) {
@@ -6470,9 +6671,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__ieee(drwav* pWav, drwav_ui
6470
6671
 
6471
6672
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6472
6673
 
6473
- drwav__ieee_to_f32(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels), bytesPerFrame/pWav->channels);
6674
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
6675
+ samplesRead = framesRead * pWav->channels;
6676
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
6677
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
6678
+ break;
6679
+ }
6474
6680
 
6475
- pBufferOut += framesRead*pWav->channels;
6681
+ drwav__ieee_to_f32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
6682
+
6683
+ pBufferOut += samplesRead;
6476
6684
  framesToRead -= framesRead;
6477
6685
  totalFramesRead += framesRead;
6478
6686
  }
@@ -6483,14 +6691,21 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__ieee(drwav* pWav, drwav_ui
6483
6691
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__alaw(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
6484
6692
  {
6485
6693
  drwav_uint64 totalFramesRead;
6486
- drwav_uint8 sampleData[4096];
6694
+ drwav_uint8 sampleData[4096] = {0};
6487
6695
  drwav_uint32 bytesPerFrame;
6696
+ drwav_uint32 bytesPerSample;
6697
+ drwav_uint64 samplesRead;
6488
6698
 
6489
6699
  bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6490
6700
  if (bytesPerFrame == 0) {
6491
6701
  return 0;
6492
6702
  }
6493
6703
 
6704
+ bytesPerSample = bytesPerFrame / pWav->channels;
6705
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
6706
+ return 0; /* Only byte-aligned formats are supported. */
6707
+ }
6708
+
6494
6709
  totalFramesRead = 0;
6495
6710
 
6496
6711
  while (framesToRead > 0) {
@@ -6502,9 +6717,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__alaw(drwav* pWav, drwav_ui
6502
6717
 
6503
6718
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6504
6719
 
6505
- drwav_alaw_to_f32(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels));
6720
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
6721
+ samplesRead = framesRead * pWav->channels;
6722
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
6723
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
6724
+ break;
6725
+ }
6726
+
6727
+ drwav_alaw_to_f32(pBufferOut, sampleData, (size_t)samplesRead);
6506
6728
 
6507
- pBufferOut += framesRead*pWav->channels;
6729
+ pBufferOut += samplesRead;
6508
6730
  framesToRead -= framesRead;
6509
6731
  totalFramesRead += framesRead;
6510
6732
  }
@@ -6515,14 +6737,21 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__alaw(drwav* pWav, drwav_ui
6515
6737
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__mulaw(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
6516
6738
  {
6517
6739
  drwav_uint64 totalFramesRead;
6518
- drwav_uint8 sampleData[4096];
6740
+ drwav_uint8 sampleData[4096] = {0};
6519
6741
  drwav_uint32 bytesPerFrame;
6742
+ drwav_uint32 bytesPerSample;
6743
+ drwav_uint64 samplesRead;
6520
6744
 
6521
6745
  bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6522
6746
  if (bytesPerFrame == 0) {
6523
6747
  return 0;
6524
6748
  }
6525
6749
 
6750
+ bytesPerSample = bytesPerFrame / pWav->channels;
6751
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
6752
+ return 0; /* Only byte-aligned formats are supported. */
6753
+ }
6754
+
6526
6755
  totalFramesRead = 0;
6527
6756
 
6528
6757
  while (framesToRead > 0) {
@@ -6534,9 +6763,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__mulaw(drwav* pWav, drwav_u
6534
6763
 
6535
6764
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6536
6765
 
6537
- drwav_mulaw_to_f32(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels));
6766
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
6767
+ samplesRead = framesRead * pWav->channels;
6768
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
6769
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
6770
+ break;
6771
+ }
6772
+
6773
+ drwav_mulaw_to_f32(pBufferOut, sampleData, (size_t)samplesRead);
6538
6774
 
6539
- pBufferOut += framesRead*pWav->channels;
6775
+ pBufferOut += samplesRead;
6540
6776
  framesToRead -= framesRead;
6541
6777
  totalFramesRead += framesRead;
6542
6778
  }
@@ -6563,8 +6799,8 @@ DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32(drwav* pWav, drwav_uint64 frame
6563
6799
  return drwav_read_pcm_frames_f32__pcm(pWav, framesToRead, pBufferOut);
6564
6800
  }
6565
6801
 
6566
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM) {
6567
- return drwav_read_pcm_frames_f32__msadpcm(pWav, framesToRead, pBufferOut);
6802
+ if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM || pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
6803
+ return drwav_read_pcm_frames_f32__msadpcm_ima(pWav, framesToRead, pBufferOut);
6568
6804
  }
6569
6805
 
6570
6806
  if (pWav->translatedFormatTag == DR_WAVE_FORMAT_IEEE_FLOAT) {
@@ -6579,10 +6815,6 @@ DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32(drwav* pWav, drwav_uint64 frame
6579
6815
  return drwav_read_pcm_frames_f32__mulaw(pWav, framesToRead, pBufferOut);
6580
6816
  }
6581
6817
 
6582
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
6583
- return drwav_read_pcm_frames_f32__ima(pWav, framesToRead, pBufferOut);
6584
- }
6585
-
6586
6818
  return 0;
6587
6819
  }
6588
6820
 
@@ -6791,8 +7023,10 @@ DRWAV_PRIVATE void drwav__ieee_to_s32(drwav_int32* pOut, const drwav_uint8* pIn,
6791
7023
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__pcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
6792
7024
  {
6793
7025
  drwav_uint64 totalFramesRead;
6794
- drwav_uint8 sampleData[4096];
7026
+ drwav_uint8 sampleData[4096] = {0};
6795
7027
  drwav_uint32 bytesPerFrame;
7028
+ drwav_uint32 bytesPerSample;
7029
+ drwav_uint64 samplesRead;
6796
7030
 
6797
7031
  /* Fast path. */
6798
7032
  if (pWav->translatedFormatTag == DR_WAVE_FORMAT_PCM && pWav->bitsPerSample == 32) {
@@ -6804,6 +7038,11 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__pcm(drwav* pWav, drwav_uin
6804
7038
  return 0;
6805
7039
  }
6806
7040
 
7041
+ bytesPerSample = bytesPerFrame / pWav->channels;
7042
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
7043
+ return 0; /* Only byte-aligned formats are supported. */
7044
+ }
7045
+
6807
7046
  totalFramesRead = 0;
6808
7047
 
6809
7048
  while (framesToRead > 0) {
@@ -6815,37 +7054,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__pcm(drwav* pWav, drwav_uin
6815
7054
 
6816
7055
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6817
7056
 
6818
- drwav__pcm_to_s32(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels), bytesPerFrame/pWav->channels);
6819
-
6820
- pBufferOut += framesRead*pWav->channels;
6821
- framesToRead -= framesRead;
6822
- totalFramesRead += framesRead;
6823
- }
6824
-
6825
- return totalFramesRead;
6826
- }
6827
-
6828
- DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__msadpcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
6829
- {
6830
- /*
6831
- We're just going to borrow the implementation from the drwav_read_s16() since ADPCM is a little bit more complicated than other formats and I don't
6832
- want to duplicate that code.
6833
- */
6834
- drwav_uint64 totalFramesRead = 0;
6835
- drwav_int16 samples16[2048];
6836
-
6837
- while (framesToRead > 0) {
6838
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, drwav_countof(samples16)/pWav->channels);
6839
- drwav_uint64 framesRead = drwav_read_pcm_frames_s16(pWav, framesToReadThisIteration, samples16);
6840
- if (framesRead == 0) {
7057
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
7058
+ samplesRead = framesRead * pWav->channels;
7059
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
7060
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
6841
7061
  break;
6842
7062
  }
6843
7063
 
6844
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6845
-
6846
- drwav_s16_to_s32(pBufferOut, samples16, (size_t)(framesRead*pWav->channels)); /* <-- Safe cast because we're clamping to 2048. */
7064
+ drwav__pcm_to_s32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
6847
7065
 
6848
- pBufferOut += framesRead*pWav->channels;
7066
+ pBufferOut += samplesRead;
6849
7067
  framesToRead -= framesRead;
6850
7068
  totalFramesRead += framesRead;
6851
7069
  }
@@ -6853,10 +7071,10 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__msadpcm(drwav* pWav, drwav
6853
7071
  return totalFramesRead;
6854
7072
  }
6855
7073
 
6856
- DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__ima(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
7074
+ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__msadpcm_ima(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
6857
7075
  {
6858
7076
  /*
6859
- We're just going to borrow the implementation from the drwav_read_s16() since IMA-ADPCM is a little bit more complicated than other formats and I don't
7077
+ We're just going to borrow the implementation from the drwav_read_s16() since ADPCM is a little bit more complicated than other formats and I don't
6860
7078
  want to duplicate that code.
6861
7079
  */
6862
7080
  drwav_uint64 totalFramesRead = 0;
@@ -6884,13 +7102,21 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__ima(drwav* pWav, drwav_uin
6884
7102
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__ieee(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
6885
7103
  {
6886
7104
  drwav_uint64 totalFramesRead;
6887
- drwav_uint8 sampleData[4096];
6888
- drwav_uint32 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
7105
+ drwav_uint8 sampleData[4096] = {0};
7106
+ drwav_uint32 bytesPerFrame;
7107
+ drwav_uint32 bytesPerSample;
7108
+ drwav_uint64 samplesRead;
6889
7109
 
7110
+ bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6890
7111
  if (bytesPerFrame == 0) {
6891
7112
  return 0;
6892
7113
  }
6893
7114
 
7115
+ bytesPerSample = bytesPerFrame / pWav->channels;
7116
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
7117
+ return 0; /* Only byte-aligned formats are supported. */
7118
+ }
7119
+
6894
7120
  totalFramesRead = 0;
6895
7121
 
6896
7122
  while (framesToRead > 0) {
@@ -6902,9 +7128,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__ieee(drwav* pWav, drwav_ui
6902
7128
 
6903
7129
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6904
7130
 
6905
- drwav__ieee_to_s32(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels), bytesPerFrame/pWav->channels);
7131
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
7132
+ samplesRead = framesRead * pWav->channels;
7133
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
7134
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
7135
+ break;
7136
+ }
6906
7137
 
6907
- pBufferOut += framesRead*pWav->channels;
7138
+ drwav__ieee_to_s32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
7139
+
7140
+ pBufferOut += samplesRead;
6908
7141
  framesToRead -= framesRead;
6909
7142
  totalFramesRead += framesRead;
6910
7143
  }
@@ -6915,13 +7148,21 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__ieee(drwav* pWav, drwav_ui
6915
7148
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__alaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
6916
7149
  {
6917
7150
  drwav_uint64 totalFramesRead;
6918
- drwav_uint8 sampleData[4096];
6919
- drwav_uint32 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
7151
+ drwav_uint8 sampleData[4096] = {0};
7152
+ drwav_uint32 bytesPerFrame;
7153
+ drwav_uint32 bytesPerSample;
7154
+ drwav_uint64 samplesRead;
6920
7155
 
7156
+ bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6921
7157
  if (bytesPerFrame == 0) {
6922
7158
  return 0;
6923
7159
  }
6924
7160
 
7161
+ bytesPerSample = bytesPerFrame / pWav->channels;
7162
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
7163
+ return 0; /* Only byte-aligned formats are supported. */
7164
+ }
7165
+
6925
7166
  totalFramesRead = 0;
6926
7167
 
6927
7168
  while (framesToRead > 0) {
@@ -6933,9 +7174,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__alaw(drwav* pWav, drwav_ui
6933
7174
 
6934
7175
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6935
7176
 
6936
- drwav_alaw_to_s32(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels));
7177
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
7178
+ samplesRead = framesRead * pWav->channels;
7179
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
7180
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
7181
+ break;
7182
+ }
6937
7183
 
6938
- pBufferOut += framesRead*pWav->channels;
7184
+ drwav_alaw_to_s32(pBufferOut, sampleData, (size_t)samplesRead);
7185
+
7186
+ pBufferOut += samplesRead;
6939
7187
  framesToRead -= framesRead;
6940
7188
  totalFramesRead += framesRead;
6941
7189
  }
@@ -6946,13 +7194,21 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__alaw(drwav* pWav, drwav_ui
6946
7194
  DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__mulaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
6947
7195
  {
6948
7196
  drwav_uint64 totalFramesRead;
6949
- drwav_uint8 sampleData[4096];
6950
- drwav_uint32 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
7197
+ drwav_uint8 sampleData[4096] = {0};
7198
+ drwav_uint32 bytesPerFrame;
7199
+ drwav_uint32 bytesPerSample;
7200
+ drwav_uint64 samplesRead;
6951
7201
 
7202
+ bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6952
7203
  if (bytesPerFrame == 0) {
6953
7204
  return 0;
6954
7205
  }
6955
7206
 
7207
+ bytesPerSample = bytesPerFrame / pWav->channels;
7208
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
7209
+ return 0; /* Only byte-aligned formats are supported. */
7210
+ }
7211
+
6956
7212
  totalFramesRead = 0;
6957
7213
 
6958
7214
  while (framesToRead > 0) {
@@ -6964,9 +7220,16 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__mulaw(drwav* pWav, drwav_u
6964
7220
 
6965
7221
  DRWAV_ASSERT(framesRead <= framesToReadThisIteration); /* If this fails it means there's a bug in drwav_read_pcm_frames(). */
6966
7222
 
6967
- drwav_mulaw_to_s32(pBufferOut, sampleData, (size_t)(framesRead*pWav->channels));
7223
+ /* Validation to ensure we don't read too much from out intermediary buffer. This is to protect from invalid files. */
7224
+ samplesRead = framesRead * pWav->channels;
7225
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
7226
+ DRWAV_ASSERT(DRWAV_FALSE); /* This should never happen with a valid file. */
7227
+ break;
7228
+ }
6968
7229
 
6969
- pBufferOut += framesRead*pWav->channels;
7230
+ drwav_mulaw_to_s32(pBufferOut, sampleData, (size_t)samplesRead);
7231
+
7232
+ pBufferOut += samplesRead;
6970
7233
  framesToRead -= framesRead;
6971
7234
  totalFramesRead += framesRead;
6972
7235
  }
@@ -6993,8 +7256,8 @@ DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32(drwav* pWav, drwav_uint64 frame
6993
7256
  return drwav_read_pcm_frames_s32__pcm(pWav, framesToRead, pBufferOut);
6994
7257
  }
6995
7258
 
6996
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM) {
6997
- return drwav_read_pcm_frames_s32__msadpcm(pWav, framesToRead, pBufferOut);
7259
+ if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM || pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
7260
+ return drwav_read_pcm_frames_s32__msadpcm_ima(pWav, framesToRead, pBufferOut);
6998
7261
  }
6999
7262
 
7000
7263
  if (pWav->translatedFormatTag == DR_WAVE_FORMAT_IEEE_FLOAT) {
@@ -7009,10 +7272,6 @@ DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32(drwav* pWav, drwav_uint64 frame
7009
7272
  return drwav_read_pcm_frames_s32__mulaw(pWav, framesToRead, pBufferOut);
7010
7273
  }
7011
7274
 
7012
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
7013
- return drwav_read_pcm_frames_s32__ima(pWav, framesToRead, pBufferOut);
7014
- }
7015
-
7016
7275
  return 0;
7017
7276
  }
7018
7277
 
@@ -7600,7 +7859,10 @@ DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b)
7600
7859
  /*
7601
7860
  REVISION HISTORY
7602
7861
  ================
7603
- v0.13.3 - TBD
7862
+ v0.13.4 - 2021-12-08
7863
+ - Fix some static analysis warnings.
7864
+
7865
+ v0.13.3 - 2021-11-24
7604
7866
  - Fix an incorrect assertion when trying to endian swap 1-byte sample formats. This is now a no-op
7605
7867
  rather than a failed assertion.
7606
7868
  - Fix a bug with parsing of the bext chunk.