Skip to content

Commit

Permalink
Update SoundExists to sanitize sound paths
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrb93 committed Aug 31, 2024
1 parent afa585c commit 4850be3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 2 additions & 3 deletions lua/entities/gmod_wire_expression2/core/sound.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ end


local function soundCreate(self, entity, index, time, path, fade)
if path:match('["?]') then return end

if not WireLib.SoundExists(path) then return end
path = WireLib.SoundExists(path)
if not path then return end
local data = self.data.sound_data
if not isAllowed( self ) then return end

Expand Down
13 changes: 6 additions & 7 deletions lua/entities/gmod_wire_soundemitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ end

function ENT:UpdateSound()
if self.NeedsRefresh or self.sound ~= self.ActiveSample then
if not WireLib.SoundExists(self.sound) then return end

self.NeedsRefresh = nil
local filter = RecipientFilter()
Expand Down Expand Up @@ -167,23 +166,23 @@ end
function ENT:SetSound(soundName)
self:StopSounds()

soundName = string.Trim(string.sub(soundName, 1, 260))
if soundName:match('["?]') then return end
util.PrecacheSound(soundName)
soundName = WireLib.SoundExists(soundName)
if not soundName then return end

util.PrecacheSound(soundName)
self.sound = soundName

self.SoundProperties = sound.GetProperties(self.sound)
self.SoundProperties = sound.GetProperties(soundName)
if self.SoundProperties then
WireLib.TriggerOutput(self, "Duration", SoundDuration(self.sound))
WireLib.TriggerOutput(self, "Duration", SoundDuration(soundName))
WireLib.TriggerOutput(self, "Property Sound", 1)
WireLib.TriggerOutput(self, "Properties", self.SoundProperties)
else
WireLib.TriggerOutput(self, "Property Sound", 0)
WireLib.TriggerOutput(self, "Properties", {})
end

self:SetOverlayText( soundName:gsub("[/\\]+","/") )
self:SetOverlayText(soundName)
end

function ENT:StartSounds()
Expand Down
6 changes: 4 additions & 2 deletions lua/wire/server/wirelib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1537,8 +1537,10 @@ if not WireLib.PatchedDuplicator then
end

function WireLib.SoundExists(path)
if istable(sound.GetProperties(path)) then return true end
if file.Exists("sound/" .. string.gsub(path, "^%W*", ""), "GAME") then return true end
path = string.GetNormalizedFilepath(string.gsub(string.sub(path, 1, 260), '["?]', ''))
if istable(sound.GetProperties(path)) or file.Exists("sound/" .. path, "GAME") then
return path
end
end

-- Notify --
Expand Down

0 comments on commit 4850be3

Please sign in to comment.