From: Sangchul Lee Date: Thu, 27 May 2021 06:01:34 +0000 (+0900) Subject: webrtc_test: Limit expected size of receiving data via data channel X-Git-Tag: submit/tizen/20210729.023123~69 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ad037ef40bbad57773d20712c8ca669f7a3c6ba3;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_test: Limit expected size of receiving data via data channel [Version] 0.1.172 [Issue Type] Test application Change-Id: I18a0ec0bc0f9925ce687859e8d3c771226d4d16c Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 54cc62fa..d06becfc 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -1,6 +1,6 @@ Name: capi-media-webrtc Summary: A WebRTC library in Tizen Native API -Version: 0.1.171 +Version: 0.1.172 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/test/webrtc_test.c b/test/webrtc_test.c index 98c1ce43..518cad3a 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -46,6 +46,7 @@ #define MAX_CHANNEL_LEN 10 #define MAX_CONNECTION_LEN 4 #define MAX_MEDIA_PACKET_SOURCE_LEN 4 +#define MAX_EXPECTED_SIZE 1024 * 1024 * 1024 #define USE_GSTBUFFER_WITHOUT_COPY true @@ -1011,9 +1012,14 @@ static void __data_channel_message_cb(webrtc_data_channel_h channel, webrtc_data str_arr = g_strsplit((const gchar *)message, ":", 2); if (__convert_string_to_gint64(str_arr[1], &conn->expected_size) == 0) { - if (conn->receive_buffer) + if (conn->receive_buffer) { free(conn->receive_buffer); - conn->receive_buffer = (char *)calloc(conn->expected_size, sizeof(char)); + conn->receive_buffer = NULL; + } + if (conn->expected_size > MAX_EXPECTED_SIZE) + g_print("expected_size[%llu], too big to alloc memory, skip it\n", conn->expected_size); + else + conn->receive_buffer = (char *)calloc(conn->expected_size, sizeof(char)); } } @@ -1032,6 +1038,11 @@ static void __data_channel_message_cb(webrtc_data_channel_h channel, webrtc_data if (conn->expected_size > 0 && conn->expected_name) { g_print("downloading [%s], size[%llu / %llu]\n", conn->expected_name, conn->sum_size, conn->expected_size); + if (conn->receive_buffer == NULL) { + g_print("receive_buffer is null, skip copying it\n"); + return; + } + memcpy(&conn->receive_buffer[conn->sum_size], ((uint8_t*)data_p), size); conn->sum_size += size;