<commit_before>/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "rtcp_receiver_help.h"
#include "rtp_utility.h"

#include <string.h> //memset
#include <cassert> //assert

namespace webrtc {
using namespace RTCPHelp;

RTCPPacketInformation::RTCPPacketInformation() :
    rtcpPacketTypeFlags(0),
    nackSequenceNumbers(0),
    nackSequenceNumbersLength(0),
    applicationSubType(0),
    applicationName(0),
    applicationData(),
    applicationLength(0),
    reportBlock(false),
    fractionLost(0),
    roundTripTime(0),
    lastReceivedExtendedHighSeqNum(0),
    jitter(0),
    sliPictureId(0),
    rpsiPictureId(0),
    VoIPMetric(NULL)
{
}

RTCPPacketInformation::~RTCPPacketInformation()
{
    delete [] nackSequenceNumbers;
    delete [] applicationData;
    delete VoIPMetric;
}

void
RTCPPacketInformation::AddVoIPMetric(const RTCPVoIPMetric* metric)
{
    VoIPMetric = new RTCPVoIPMetric();
    memcpy(VoIPMetric, metric, sizeof(RTCPVoIPMetric));
}

void
RTCPPacketInformation::AddApplicationData(const WebRtc_UWord8* data, const WebRtc_UWord16 size)
{
    WebRtc_UWord8* oldData = applicationData;
    WebRtc_UWord16 oldLength = applicationLength;

    applicationLength += size;
    applicationData = new WebRtc_UWord8[applicationLength];

    if(oldData)
    {
        memcpy(applicationData, oldData, oldLength);
        memcpy(applicationData+oldLength, data, size);
        delete [] oldData;
    } else
    {
        memcpy(applicationData, data, size);
    }
}

void
RTCPPacketInformation::ResetNACKPacketIdArray()
{
    if(NULL == nackSequenceNumbers)
    {
        nackSequenceNumbers = new WebRtc_UWord16[NACK_PACKETS_MAX_SIZE];
    }
    nackSequenceNumbersLength = 0;
}

void
RTCPPacketInformation::AddNACKPacket(const WebRtc_UWord16 packetID)
{
    assert(nackSequenceNumbers);
<commit_msg>Added size sanity check for copying app specific RTCP data.<commit_after>/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "rtcp_receiver_help.h"
#include "rtp_utility.h"

#include <string.h> //memset
#include <cassert> //assert

namespace webrtc {
using namespace RTCPHelp;

RTCPPacketInformation::RTCPPacketInformation() :
    rtcpPacketTypeFlags(0),
    nackSequenceNumbers(0),
    nackSequenceNumbersLength(0),
    applicationSubType(0),
    applicationName(0),
    applicationData(),
    applicationLength(0),
    reportBlock(false),
    fractionLost(0),
    roundTripTime(0),
    lastReceivedExtendedHighSeqNum(0),
    jitter(0),
    sliPictureId(0),
    rpsiPictureId(0),
    VoIPMetric(NULL)
{
}

RTCPPacketInformation::~RTCPPacketInformation()
{
    delete [] nackSequenceNumbers;
    delete [] applicationData;
    delete VoIPMetric;
}

void
RTCPPacketInformation::AddVoIPMetric(const RTCPVoIPMetric* metric)
{
    VoIPMetric = new RTCPVoIPMetric();
    memcpy(VoIPMetric, metric, sizeof(RTCPVoIPMetric));
}

void
RTCPPacketInformation::AddApplicationData(const WebRtc_UWord8* data, const WebRtc_UWord16 size)
{
    WebRtc_UWord8* oldData = applicationData;
    WebRtc_UWord16 oldLength = applicationLength;

    // Don't copy more than kRtcpAppCode_DATA_SIZE bytes.
    if (size > kRtcpAppCode_DATA_SIZE) {
        size = kRtcpAppCode_DATA_SIZE;
    }

    applicationLength += size;
    applicationData = new WebRtc_UWord8[applicationLength];

    if(oldData)
    {
        memcpy(applicationData, oldData, oldLength);
        memcpy(applicationData+oldLength, data, size);
        delete [] oldData;
    } else
    {
        memcpy(applicationData, data, size);
    }
}

void
RTCPPacketInformation::ResetNACKPacketIdArray()
{
    if(NULL == nackSequenceNumbers)
    {
        nackSequenceNumbers = new WebRtc_UWord16[NACK_PACKETS_MAX_SIZE];
    }
    nackSequenceNumbersLength = 0;
}

void
RTCPPacketInformation::AddNACKPacket(const WebRtc_UWord16 packetID)
{
    assert(nackSequenceNumbers);

{'fraction_non_alphanumeric': 0.08889862053864682, 'fraction_numerical': 0.012261878694985767, 'mean_word_length': 4.173272933182333, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3097843', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1421, 'n_words': 342}