webrtc_test: Limit expected size of receiving data via data channel 83/258883/1
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 27 May 2021 06:01:34 +0000 (15:01 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 27 May 2021 06:01:44 +0000 (15:01 +0900)
[Version] 0.1.172
[Issue Type] Test application

Change-Id: I18a0ec0bc0f9925ce687859e8d3c771226d4d16c
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
test/webrtc_test.c

index 54cc62fa2ba11859ef0c5f9ab88918ef9a527e31..d06becfc33c402a98f611e7d32673e6143ce90ba 100644 (file)
@@ -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
index 98c1ce436bd6d2e211896f3166551896464ae63b..518cad3a8f1724b39c6a74e53bdead234a12c668 100644 (file)
@@ -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;