Skip to content

Commit 2b66deb

Browse files
IcebluewolfLulalaby
authored andcommitted
fix: Add Checks For Payload Type And Header Length
1 parent 756de66 commit 2b66deb

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ def _decrypt_aead_xchacha20_poly1305_rtpsize(self, header, data):
639639
nonce = bytearray(24)
640640
nonce[:4] = data[-4:]
641641
data = data[:-4]
642+
print(bytes(data))
643+
print(bytes(header))
642644

643645
return self.strip_header_ext(
644646
box.decrypt(bytes(data), bytes(header), bytes(nonce))
@@ -762,11 +764,12 @@ def unpack_audio(self, data):
762764
data: :class:`bytes`
763765
Bytes received by Discord via the UDP connection used for sending and receiving voice data.
764766
"""
765-
if 200 <= data[1] <= 204:
766-
# RTCP received.
767-
# RTCP provides information about the connection
768-
# as opposed to actual audio data, so it's not
769-
# important at the moment.
767+
if data[1] != 0x78:
768+
# We Should Ignore Any Payload Types We Do Not Understand
769+
# Ref RFC 3550 5.1 payload type
770+
# At Some Point We Noted That We Should Ignore Only Types 200 - 204 inclusive.
771+
# They Were Marked As RTCP: Provides Information About The Connection
772+
# This Was Too Broad Of A Whitelist, It Is Unclear If This Is Too Narrow Of A Whitelist
770773
return
771774
if self.paused:
772775
return

0 commit comments

Comments
 (0)