Skip to content

Commit

Permalink
RtspClient - fix possible unintentional overflow
Browse files Browse the repository at this point in the history
static PlatformNotSupportedException
  • Loading branch information
juliusfriedman committed Nov 21, 2023
1 parent b6cbe66 commit 0664cc9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
6 changes: 4 additions & 2 deletions Common/Extensions/ThreadExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public static bool IsRunning(System.Threading.Thread thread)
(thread.ThreadState & (System.Threading.ThreadState.Stopped | System.Threading.ThreadState.Unstarted)) == System.Threading.ThreadState.Running;
}

static readonly System.PlatformNotSupportedException ThreadAbortNotSupported = new ("Thread.Abort is not supported. Ensure your thread has stopped.");

/// <summary>
/// Calls <see cref="Interrupt"/> on the given thread and indicates if the interrupt was received back.
/// </summary>
Expand All @@ -78,7 +80,7 @@ public static void AbortAndFree(ref System.Threading.Thread thread, System.Threa
//Attempt to join
if (thread.Join(timeout) is false)
{
throw new System.PlatformNotSupportedException("Thread.Abort is not supported. Ensure your thread has stopped.");
throw ThreadAbortNotSupported;
}

//Reset the state of the thread to indicate success
Expand All @@ -101,7 +103,7 @@ public static void AbortAndFree(ref System.Threading.Thread thread, System.TimeS
IsRunning(thread) &&
thread.Join(timeout) is false)
{
throw new System.PlatformNotSupportedException("Thread.Abort is not supported. Ensure your thread has stopped.");
throw ThreadAbortNotSupported;
}
}

Expand Down
4 changes: 1 addition & 3 deletions Rtsp/RtspClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2472,10 +2472,8 @@ SharesSocket is false &&
//Incrment for justReceived
received += justReceived;

int contentLength = interleaved.ContentLength;

//Ensure we are not doing to much receiving
if (contentLength >= 0 && received > RtspMessage.MaximumLength + contentLength)
if (received > RtspMessage.MaximumLength)
{
if (Common.IDisposedExtensions.IsNullOrDisposed(interleaved) &&
interleaved.IsPersistent)
Expand Down
2 changes: 1 addition & 1 deletion RtspServer/ClientSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ internal RtspMessage ProcessPause(RtspMessage request, RtpSource source)
foreach (RtpClient.TransportContext sourceContext in source.RtpClient.GetTransportContexts())
{
//Adding the id will stop the packets from being enqueued into the RtpClient
PacketBuffer.Add((int)sourceContext.SynchronizationSourceIdentifier);
PacketBuffer.Add(sourceContext.SynchronizationSourceIdentifier);
}

//Return the response
Expand Down
3 changes: 1 addition & 2 deletions UnitTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,6 @@ static void TestRtspClient(string location, System.Net.NetworkCredential cred =
/// </summary>
static async Task TestServerAsync()
{

Console.WriteLine(nameof(TestServerAsync));

System.Runtime.GCLatencyMode oldMode = System.Runtime.GCSettings.LatencyMode;
Expand Down Expand Up @@ -2482,7 +2481,7 @@ static async Task TestServerAsync()
{
//Streams lookup the packet by the ssrc, this could be changed to use the payload type etc
rtp.SynchronizationSourceIdentifier = rtpDumpAudioStream.SourceId;
rtpDumpAudioStream.Frames.Enqueue(new RtpFrame { rtp });
rtpDumpAudioStream.Frames.Enqueue([rtp]);
}
}
}
Expand Down

0 comments on commit 0664cc9

Please sign in to comment.