Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1054e74 authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Revert "Move overflow checks into SkipCutBuffer"

This reverts commit 6867e1a1.

Change-Id: I90d479dac014c72ffa7151a30e79e68d9ce967ac
parent 6867e1a1
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -29,10 +29,9 @@ namespace android {
 */
class SkipCutBuffer: public RefBase {
 public:
    // 'skip' is the number of frames to skip from the beginning
    // 'cut' is the number of frames to cut from the end
    // 'num16BitChannels' is the number of channels, which are assumed to be 16 bit wide each
    SkipCutBuffer(size_t skip, size_t cut, size_t num16Channels);
    // 'skip' is the number of bytes to skip from the beginning
    // 'cut' is the number of bytes to cut from the end
    SkipCutBuffer(int32_t skip, int32_t cut);

    // Submit one MediaBuffer for skipping and cutting. This may consume all or
    // some of the data in the buffer, or it may add data to it.
+4 −1
Original line number Diff line number Diff line
@@ -4438,13 +4438,16 @@ void ACodec::sendFormatChange(const sp<AMessage> &reply) {
               (mEncoderDelay || mEncoderPadding)) {
        int32_t channelCount;
        CHECK(notify->findInt32("channel-count", &channelCount));
        size_t frameSize = channelCount * sizeof(int16_t);
        if (mSkipCutBuffer != NULL) {
            size_t prevbufsize = mSkipCutBuffer->size();
            if (prevbufsize != 0) {
                ALOGW("Replacing SkipCutBuffer holding %zu bytes", prevbufsize);
            }
        }
        mSkipCutBuffer = new SkipCutBuffer(mEncoderDelay, mEncoderPadding, channelCount);
        mSkipCutBuffer = new SkipCutBuffer(
                mEncoderDelay * frameSize,
                mEncoderPadding * frameSize);
    }

    notify->post();
+2 −1
Original line number Diff line number Diff line
@@ -1751,13 +1751,14 @@ status_t OMXCodec::allocateBuffersOnPort(OMX_U32 portIndex) {
        int32_t numchannels = 0;
        if (delay + padding) {
            if (mOutputFormat->findInt32(kKeyChannelCount, &numchannels)) {
                size_t frameSize = numchannels * sizeof(int16_t);
                if (mSkipCutBuffer != NULL) {
                    size_t prevbuffersize = mSkipCutBuffer->size();
                    if (prevbuffersize != 0) {
                        ALOGW("Replacing SkipCutBuffer holding %zu bytes", prevbuffersize);
                    }
                }
                mSkipCutBuffer = new SkipCutBuffer(delay, padding, numchannels);
                mSkipCutBuffer = new SkipCutBuffer(delay * frameSize, padding * frameSize);
            }
        }
    }
+8 −29
Original line number Diff line number Diff line
@@ -24,31 +24,20 @@

namespace android {

SkipCutBuffer::SkipCutBuffer(size_t skip, size_t cut, size_t num16BitChannels) {
SkipCutBuffer::SkipCutBuffer(int32_t skip, int32_t cut) {

    mWriteHead = 0;
    mReadHead = 0;
    mCapacity = 0;
    mCutBuffer = NULL;

    if (num16BitChannels == 0 || num16BitChannels > SIZE_MAX / 2) {
        ALOGW("# channels out of range: %zu, using passthrough instead", num16BitChannels);
        return;
    if (skip < 0 || cut < 0 || cut > 64 * 1024) {
        ALOGW("out of range skip/cut: %d/%d, using passthrough instead", skip, cut);
        skip = 0;
        cut = 0;
    }
    size_t frameSize = num16BitChannels * 2;
    if (skip > SIZE_MAX / frameSize || cut > SIZE_MAX / frameSize
            || cut * frameSize > SIZE_MAX - 4096) {
        ALOGW("out of range skip/cut: %zu/%zu, using passthrough instead",
                skip, cut);
        return;
    }
    skip *= frameSize;
    cut *= frameSize;

    mFrontPadding = mSkip = skip;
    mBackPadding = cut;
    mWriteHead = 0;
    mReadHead = 0;
    mCapacity = cut + 4096;
    mCutBuffer = new (std::nothrow) char[mCapacity];
    mCutBuffer = new char[mCapacity];
    ALOGV("skipcutbuffer %d %d %d", skip, cut, mCapacity);
}

@@ -57,11 +46,6 @@ SkipCutBuffer::~SkipCutBuffer() {
}

void SkipCutBuffer::submit(MediaBuffer *buffer) {
    if (mCutBuffer == NULL) {
        // passthrough mode
        return;
    }

    int32_t offset = buffer->range_offset();
    int32_t buflen = buffer->range_length();

@@ -89,11 +73,6 @@ void SkipCutBuffer::submit(MediaBuffer *buffer) {
}

void SkipCutBuffer::submit(const sp<ABuffer>& buffer) {
    if (mCutBuffer == NULL) {
        // passthrough mode
        return;
    }

    int32_t offset = buffer->offset();
    int32_t buflen = buffer->size();