#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
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));
}
}
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;