From: Wonsik Kim Date: Wed, 22 Jun 2016 18:19:15 +0000 (+0000) Subject: Revert "Impose a size bound for dynamically allocated tables in stbl." X-Git-Tag: android-x86-7.1-r1~3^2~54^2~14^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=66c4dbb96c38630d0cd6551fc8c9bf8fa3318903;p=android-x86%2Fframeworks-av.git Revert "Impose a size bound for dynamically allocated tables in stbl." This reverts commit 25e029746796fe88e82417fb01af2e27b8bbadb2. Change-Id: I91225838a8be72a3cd413f2bcb99e7dca7e62929 --- diff --git a/include/media/stagefright/DataSource.h b/include/media/stagefright/DataSource.h index 22bc44d564..6c64a2c033 100644 --- a/include/media/stagefright/DataSource.h +++ b/include/media/stagefright/DataSource.h @@ -27,7 +27,6 @@ #include #include #include -#include namespace android { @@ -70,7 +69,7 @@ public: // The default value for chunkSize is set to read at least 4k bytes at a // time, depending on sizeof(T). template - bool getVector(off64_t offset, std::vector* x, size_t count, + bool getVector(off64_t offset, Vector* x, size_t count, size_t chunkSize = (4095 / sizeof(T)) + 1); // May return ERROR_UNSUPPORTED. @@ -124,7 +123,7 @@ private: }; template -bool DataSource::getVector(off64_t offset, std::vector* x, size_t count, +bool DataSource::getVector(off64_t offset, Vector* x, size_t count, size_t chunkSize) { x->clear(); @@ -150,11 +149,10 @@ bool DataSource::getVector(off64_t offset, std::vector* x, size_t count, if (numBytesRead < numBytesPerChunk) { // This case is triggered when the stream ends before the whole // chunk is read. - x->insert(x->end(), &tmp[0], - &tmp[(size_t)numBytesRead / sizeof(T)]); + x->appendArray(tmp, (size_t)numBytesRead / sizeof(T)); return false; } - x->insert(x->end(), &tmp[0], &tmp[chunkSize]); + x->appendArray(tmp, chunkSize); offset += numBytesPerChunk; } @@ -165,7 +163,7 @@ bool DataSource::getVector(off64_t offset, std::vector* x, size_t count, if (numBytesRead == -1) { return false; } - x->insert(x->end(), &tmp[0], &tmp[(size_t)numBytesRead / sizeof(T)]); + x->appendArray(tmp, (size_t)numBytesRead / sizeof(T)); return x->size() == count; } diff --git a/media/libstagefright/SampleTable.cpp b/media/libstagefright/SampleTable.cpp index 1710da641a..b71c4a7d86 100644 --- a/media/libstagefright/SampleTable.cpp +++ b/media/libstagefright/SampleTable.cpp @@ -132,8 +132,7 @@ SampleTable::SampleTable(const sp &source) mNumSyncSamples(0), mSyncSamples(NULL), mLastSyncSampleIndex(0), - mSampleToChunkEntries(NULL), - mTotalSize(0) { + mSampleToChunkEntries(NULL) { mSampleIterator = new SampleIterator(this); } @@ -235,33 +234,11 @@ status_t SampleTable::setSampleToChunkParams( } if (SIZE_MAX / sizeof(SampleToChunkEntry) <= mNumSampleToChunkOffsets) - ALOGE("Sample-to-chunk table size too large."); return ERROR_OUT_OF_RANGE; - } - - mTotalSize += (size_t)mNumSampleToChunkOffsets * - sizeof(SampleToChunkEntry); - if (mTotalSize > kMaxTotalSize) { - ALOGE("Sample-to-chunk table size would make sample table too large.\n" - " Requested sample-to-chunk table size = %llu\n" - " Eventual sample table size >= %llu\n" - " Allowed sample table size = %llu\n", - (unsigned long long)mNumSampleToChunkOffsets * - sizeof(SampleToChunkEntry), - (unsigned long long)mTotalSize, - (unsigned long long)kMaxTotalSize); - return ERROR_OUT_OF_RANGE; - } mSampleToChunkEntries = new SampleToChunkEntry[mNumSampleToChunkOffsets]; - if ((off64_t)(SIZE_MAX - 8 - - ((mNumSampleToChunkOffsets - 1) * sizeof(SampleToChunkEntry))) - < mSampleToChunkOffset) { - return ERROR_MALFORMED; - } - for (uint32_t i = 0; i < mNumSampleToChunkOffsets; ++i) { uint8_t buffer[12]; if (mDataSource->readAt( @@ -371,33 +348,20 @@ status_t SampleTable::setTimeToSampleParams( // 2) mTimeToSampleCount is the number of entries of the time-to-sample // table. // 3) We hope that the table size does not exceed UINT32_MAX. - ALOGE("Time-to-sample table size too large."); + ALOGE(" Error: Time-to-sample table size too large."); return ERROR_OUT_OF_RANGE; } // Note: At this point, we know that mTimeToSampleCount * 2 will not // overflow because of the above condition. - - mTotalSize += (uint64_t)mTimeToSampleCount * 2 * sizeof(uint32_t); - if (mTotalSize > kMaxTotalSize) { - ALOGE("Time-to-sample table size would make sample table too large.\n" - " Requested time-to-sample table size = %llu\n" - " Eventual sample table size >= %llu\n" - " Allowed sample table size = %llu\n", - (unsigned long long)mTimeToSampleCount * 2 * sizeof(uint32_t), - (unsigned long long)mTotalSize, - (unsigned long long)kMaxTotalSize); - return ERROR_OUT_OF_RANGE; - } - if (!mDataSource->getVector(data_offset + 8, &mTimeToSample, mTimeToSampleCount * 2)) { - ALOGE("Incomplete data read for time-to-sample table."); + ALOGE(" Error: Incomplete data read for time-to-sample table."); return ERROR_IO; } for (size_t i = 0; i < mTimeToSample.size(); ++i) { - mTimeToSample[i] = ntohl(mTimeToSample[i]); + mTimeToSample.editItemAt(i) = ntohl(mTimeToSample[i]); } mHasTimeToSample = true; @@ -433,26 +397,14 @@ status_t SampleTable::setCompositionTimeToSampleParams( mNumCompositionTimeDeltaEntries = numEntries; uint64_t allocSize = (uint64_t)numEntries * 2 * sizeof(uint32_t); if (allocSize > SIZE_MAX) { - ALOGE("Composition-time-to-sample table size too large."); - return ERROR_OUT_OF_RANGE; - } - - mTotalSize += allocSize; - if (mTotalSize > kMaxTotalSize) { - ALOGE("Composition-time-to-sample table would make sample table too large.\n" - " Requested composition-time-to-sample table size = %llu\n" - " Eventual sample table size >= %llu\n" - " Allowed sample table size = %llu\n", - (unsigned long long)allocSize, - (unsigned long long)mTotalSize, - (unsigned long long)kMaxTotalSize); return ERROR_OUT_OF_RANGE; } mCompositionTimeDeltaEntries = new uint32_t[2 * numEntries]; - if (mDataSource->readAt(data_offset + 8, mCompositionTimeDeltaEntries, - (size_t)allocSize) < (ssize_t)allocSize) { + if (mDataSource->readAt( + data_offset + 8, mCompositionTimeDeltaEntries, numEntries * 8) + < (ssize_t)numEntries * 8) { delete[] mCompositionTimeDeltaEntries; mCompositionTimeDeltaEntries = NULL; @@ -495,28 +447,13 @@ status_t SampleTable::setSyncSampleParams(off64_t data_offset, size_t data_size) uint64_t allocSize = mNumSyncSamples * (uint64_t)sizeof(uint32_t); if (allocSize > SIZE_MAX) { - ALOGE("Sync sample table size too large."); - return ERROR_OUT_OF_RANGE; - } - - mTotalSize += allocSize; - if (mTotalSize > kMaxTotalSize) { - ALOGE("Sync sample table size would make sample table too large.\n" - " Requested sync sample table size = %llu\n" - " Eventual sample table size >= %llu\n" - " Allowed sample table size = %llu\n", - (unsigned long long)allocSize, - (unsigned long long)mTotalSize, - (unsigned long long)kMaxTotalSize); return ERROR_OUT_OF_RANGE; } - mSyncSamples = new (std::nothrow) uint32_t[mNumSyncSamples]; - if (!mSyncSamples) - return ERROR_OUT_OF_RANGE; - - if (mDataSource->readAt(mSyncSampleOffset + 8, mSyncSamples, - (size_t)allocSize) != (ssize_t)allocSize) { + mSyncSamples = new uint32_t[mNumSyncSamples]; + size_t size = mNumSyncSamples * sizeof(uint32_t); + if (mDataSource->readAt(mSyncSampleOffset + 8, mSyncSamples, size) + != (ssize_t)size) { return ERROR_IO; } @@ -584,21 +521,7 @@ void SampleTable::buildSampleEntriesTable() { return; } - mTotalSize += (uint64_t)mNumSampleSizes * sizeof(SampleTimeEntry); - if (mTotalSize > kMaxTotalSize) { - ALOGE("Sample entry table size would make sample table too large.\n" - " Requested sample entry table size = %llu\n" - " Eventual sample table size >= %llu\n" - " Allowed sample table size = %llu\n", - (unsigned long long)mNumSampleSizes * sizeof(SampleTimeEntry), - (unsigned long long)mTotalSize, - (unsigned long long)kMaxTotalSize); - return; - } - - mSampleTimeEntries = new (std::nothrow) SampleTimeEntry[mNumSampleSizes]; - if (!mSampleTimeEntries) - return; + mSampleTimeEntries = new SampleTimeEntry[mNumSampleSizes]; uint32_t sampleIndex = 0; uint32_t sampleTime = 0; diff --git a/media/libstagefright/include/SampleTable.h b/media/libstagefright/include/SampleTable.h index 82f1486581..caa028a148 100644 --- a/media/libstagefright/include/SampleTable.h +++ b/media/libstagefright/include/SampleTable.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include namespace android { @@ -94,9 +94,6 @@ private: static const uint32_t kSampleSizeType32; static const uint32_t kSampleSizeTypeCompact; - // Limit the total size of all internal tables to 200MiB. - static const size_t kMaxTotalSize = 200 * (1 << 20); - sp mDataSource; Mutex mLock; @@ -114,7 +111,7 @@ private: bool mHasTimeToSample; uint32_t mTimeToSampleCount; - std::vector mTimeToSample; + Vector mTimeToSample; struct SampleTimeEntry { uint32_t mSampleIndex; @@ -140,9 +137,6 @@ private: }; SampleToChunkEntry *mSampleToChunkEntries; - // Approximate size of all tables combined. - uint64_t mTotalSize; - friend struct SampleIterator; status_t getSampleSize_l(uint32_t sample_index, size_t *sample_size);