Skip to content

Commit

Permalink
Merge pull request #118 from aws-samples/buffer_fix
Browse files Browse the repository at this point in the history
C302: fix an issue that insufficient buffer might cause segmentation fault
  • Loading branch information
codingspirit authored Dec 15, 2023
2 parents 4b442b0 + 66fc975 commit 31a8f53
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/C302/C302AudioCapturer.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ int audioCapturerGetFrame(AudioCapturerHandle handle, void* pFrameDataBuffer, co
// KVS_LOG("IPC_AUDIO_GetFrame failed");
return -EAGAIN;
}
if (audioHandle->aframe->u32len > frameDataBufferSize) {
KVS_LOG("Audio buffer is too small\n");
return -EAGAIN;
}
memcpy(pFrameDataBuffer, (void*) audioHandle->aframe->u8data, audioHandle->aframe->u32len);
*pFrameSize = audioHandle->aframe->u32len;
*pTimestamp = audioHandle->aframe->u64pts;
Expand Down
5 changes: 5 additions & 0 deletions source/C302/C302AudioPlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ int audioPlayerWriteFrame(AudioPlayerHandle handle, void* pData, const size_t si
#ifdef USING_HARD_STREAM_AUDIO
int ret = 0;

if (size > audioHandle->aframe.u32len) {
KVS_LOG("AO device buffer too small");
return -EAGAIN;
}

memcpy(audioHandle->aframe.u8data, pData, size);
ret = IPC_AUDIO_SendFrame(&audioHandle->aframe);
if (ret < 0) {
Expand Down
4 changes: 4 additions & 0 deletions source/C302/C302VideoCapturer.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ int videoCapturerGetFrame(VideoCapturerHandle handle, void* pFrameDataBuffer, co
ret = IPC_VIDEO_GetFrame(&videoHandle->vframe, DEFAULT_STREAM_CHN, 0);
if (ret > 0) {
// KVS_LOG("IPC_VIDEO_GetFrame:%u\n", videoHandle->vframe.u32len);
if (videoHandle->vframe.u32len > frameDataBufferSize) {
KVS_LOG("Video buffer is too small\n");
return -EAGAIN;
}
memcpy(pFrameDataBuffer, videoHandle->vframe.u8data, videoHandle->vframe.u32len);
*pFrameSize = videoHandle->vframe.u32len;
*pTimestamp = videoHandle->vframe.u64pts;
Expand Down

0 comments on commit 31a8f53

Please sign in to comment.