Fix SIGSEGV in gst-kvs-plugin video-only pipeline when WebRTC is enabled#480
Open
narutaro wants to merge 1 commit intoaws-samples:masterfrom
Open
Fix SIGSEGV in gst-kvs-plugin video-only pipeline when WebRTC is enabled#480narutaro wants to merge 1 commit intoaws-samples:masterfrom
narutaro wants to merge 1 commit intoaws-samples:masterfrom
Conversation
When using kvsplugin with a video-only GStreamer pipeline (no audio pad) and connect-webrtc=true, the plugin crashes with SIGSEGV when a WebRTC viewer connects due to two NULL pointer dereferences: 1. createWebRtcStreamingSession(): audioContentType is NULL when no audio pad is connected, causing STRNCMP to segfault. Added NULL check and inactive audio transceiver fallback to maintain SDP m-line order. 2. handleOffer(): receiveGstreamerAudioVideo() thread unconditionally accesses pAudioRtcRtpTransceiver which is NULL without audio. Added NULL guard to skip thread creation.
sirknightj
reviewed
Mar 12, 2026
Contributor
sirknightj
left a comment
There was a problem hiding this comment.
Thank you for the contribution
| audioTrack.codec = RTC_CODEC_ALAW; | ||
| } else if (STRNCMP(pGstKvsPlugin->gstParams.audioContentType, AUDIO_OPUS_CONTENT_TYPE, MAX_GSTREAMER_MEDIA_TYPE_LEN) == 0) { | ||
| audioTrack.codec = RTC_CODEC_OPUS; | ||
| // [KVS-DUAL-STREAM-TEST] Skip audio transceiver if no audio content type (video-only pipeline) |
Contributor
There was a problem hiding this comment.
Wondering what's up with the "dual stream test" prefix in some comments?
unicornss
reviewed
Mar 12, 2026
Contributor
unicornss
left a comment
There was a problem hiding this comment.
Thanks for your contribution!
| STRCPY(audioTrack.trackId, "myAudioTrack"); | ||
| RtcRtpTransceiverInit transceiverInit; | ||
| transceiverInit.direction = RTC_RTP_TRANSCEIVER_DIRECTION_INACTIVE; | ||
| CHK_STATUS(addTransceiver(pStreamingSession->pPeerConnection, &audioTrack, &transceiverInit, &pStreamingSession->pAudioRtcRtpTransceiver)); |
Contributor
There was a problem hiding this comment.
should it also have the transceiverOnBandwidthEstimation ?
| audioTrack.codec = RTC_CODEC_OPUS; | ||
| STRCPY(audioTrack.streamId, "myKvsVideoStream"); | ||
| STRCPY(audioTrack.trackId, "myAudioTrack"); | ||
| RtcRtpTransceiverInit transceiverInit; |
Contributor
There was a problem hiding this comment.
RtcRtpTransceiverInit transceiverInit = {0}; // or memset?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
kvspluginwith a video-only GStreamer pipeline (no audio pad) andconnect-webrtc=true, the plugin crashes with SIGSEGV when a WebRTC viewer connects.Two NULL pointer dereferences occur:
createWebRtcStreamingSession():pGstKvsPlugin->gstParams.audioContentTypeis NULL when no audio pad is connected. This NULL pointer is passed toSTRNCMP(), causing a segfault.handleOffer():receiveGstreamerAudioVideo()thread is unconditionally started, but accessespStreamingSession->pAudioRtcRtpTransceiverwhich is NULL when no audio transceiver was created.Additionally, simply skipping the audio transceiver causes the SDP answer m-line order to not match the offer, resulting in the viewer rejecting the answer.
Reproduce
Connect a viewer from the KVS WebRTC test page with
useTrickleICEenabled → SIGSEGV.Fix
Change 1: NULL check for audioContentType + inactive fallback transceiver
In
createWebRtcStreamingSession(), wrap the audio codec selection in a NULL check. WhenaudioContentTypeis NULL (video-only pipeline), add an inactive audio transceiver with Opus codec to maintain SDP m-line order compatibility with the viewer's offer.Change 2: Guard receiveGstreamerAudioVideo thread
In
handleOffer(), only start thereceiveGstreamerAudioVideothread whenpAudioRtcRtpTransceiveris not NULL.Testing
Tested on Ubuntu EC2 (x86_64) with WebRTC SDK v1.7.3:
enable-streaming=false)enable-streaming=true)