Skip to content

Commit 9003ef4

Browse files
authored
Merge pull request #2 from Icebluewolf/voice_dep
fix: Add Checks For Payload Type And Header Length
2 parents 1ff9a19 + 7f18716 commit 9003ef4

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

discord/sinks/core.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,22 @@ def __init__(self, data, client):
107107
self.data = bytearray(data)
108108
self.client = client
109109

110-
self.header = data[:12]
111-
self.data = self.data[12:]
112-
113110
unpacker = struct.Struct(">xxHII")
114-
self.sequence, self.timestamp, self.ssrc = unpacker.unpack_from(self.header)
111+
self.sequence, self.timestamp, self.ssrc = unpacker.unpack_from(self.data[:12])
112+
113+
# RFC3550 5.1: RTP Fixed Header Fields
114+
if self.client.mode.endswith("_rtpsize"):
115+
# If It Has CSRC Chunks
116+
cutoff = 12 + (data[0] & 0b00_0_0_1111) * 4
117+
# If It Has A Extension
118+
if data[0] & 0b00_0_1_0000:
119+
cutoff += 4
120+
else:
121+
cutoff = 12
122+
123+
self.header = data[:cutoff]
124+
self.data = self.data[cutoff:]
125+
115126
self.decrypted_data = getattr(self.client, f"_decrypt_{self.client.mode}")(
116127
self.header, self.data
117128
)

discord/voice_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,12 @@ def unpack_audio(self, data):
761761
data: :class:`bytes`
762762
Bytes received by Discord via the UDP connection used for sending and receiving voice data.
763763
"""
764-
if 200 <= data[1] <= 204:
765-
# RTCP received.
766-
# RTCP provides information about the connection
767-
# as opposed to actual audio data, so it's not
768-
# important at the moment.
764+
if data[1] != 0x78:
765+
# We Should Ignore Any Payload Types We Do Not Understand
766+
# Ref RFC 3550 5.1 payload type
767+
# At Some Point We Noted That We Should Ignore Only Types 200 - 204 inclusive.
768+
# They Were Marked As RTCP: Provides Information About The Connection
769+
# This Was Too Broad Of A Whitelist, It Is Unclear If This Is Too Narrow Of A Whitelist
769770
return
770771
if self.paused:
771772
return

0 commit comments

Comments
 (0)