Commit 99156461 authored by Wei Jia's avatar Wei Jia Committed by The Android Automerger
Browse files

libstagefright: fix handling of mSampleTimeEntries and mNumSampleSizes in SampleTable.

Bug: 23247055
Change-Id: I29ef59c7ff09248063714e5013f7c33f66c5eebd
(cherry picked from commit 3564c456)
(cherry picked from commit 108cd2dc)
parent 749cc1e7
......@@ -27,6 +27,11 @@
#include <media/stagefright/DataSource.h>
#include <media/stagefright/Utils.h>
/* TODO: remove after being merged into other branches */
#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif
namespace android {
// static
......@@ -282,6 +287,9 @@ status_t SampleTable::setSampleSizeParams(
mDefaultSampleSize = U32_AT(&header[4]);
mNumSampleSizes = U32_AT(&header[8]);
if (mNumSampleSizes > (UINT32_MAX - 12) / 16) {
return ERROR_MALFORMED;
}
if (type == kSampleSizeType32) {
mSampleSizeFieldSize = 32;
......@@ -498,7 +506,7 @@ int SampleTable::CompareIncreasingTime(const void *_a, const void *_b) {
void SampleTable::buildSampleEntriesTable() {
Mutex::Autolock autoLock(mLock);
if (mSampleTimeEntries != NULL) {
if (mSampleTimeEntries != NULL || mNumSampleSizes == 0) {
return;
}
......@@ -541,6 +549,10 @@ status_t SampleTable::findSampleAtTime(
uint32_t *sample_index, uint32_t flags) {
buildSampleEntriesTable();
if (mSampleTimeEntries == NULL) {
return ERROR_OUT_OF_RANGE;
}
uint32_t left = 0;
uint32_t right_plus_one = mNumSampleSizes;
while (left < right_plus_one) {
......
......@@ -142,8 +142,9 @@ private:
// normally we don't round
inline uint64_t getSampleTime(
size_t sample_index, uint64_t scale_num, uint64_t scale_den) const {
return (mSampleTimeEntries[sample_index].mCompositionTime
* scale_num) / scale_den;
return (sample_index < (size_t)mNumSampleSizes && mSampleTimeEntries != NULL
&& scale_den != 0)
? (mSampleTimeEntries[sample_index].mCompositionTime * scale_num) / scale_den : 0;
}
status_t getSampleSize_l(uint32_t sample_index, size_t *sample_size);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment