diff options
author | Andreas Huber <andih@google.com> | 2011-11-07 11:38:14 -0800 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2011-11-07 11:38:14 -0800 |
commit | 8f76ebf90d0391a4baa8a921ed6e291dfc7891da (patch) | |
tree | e1f3a27e143aeeb7c5003df546ad5706e847d8c3 /media/libstagefright/SampleTable.cpp | |
parent | 14da736f1707a6dbefa52405e910ecb1b3bc2dd2 (diff) | |
download | frameworks_av-8f76ebf90d0391a4baa8a921ed6e291dfc7891da.zip frameworks_av-8f76ebf90d0391a4baa8a921ed6e291dfc7891da.tar.gz frameworks_av-8f76ebf90d0391a4baa8a921ed6e291dfc7891da.tar.bz2 |
Use binary search to discover closest sync sample index, replace
assertions with runtime errors in case the file's table of sync sample
indices is not sorted properly.
Change-Id: Ie4446a44e613a8d329ac680c37361d4407d22520
related-to-bug: 5549855
Diffstat (limited to 'media/libstagefright/SampleTable.cpp')
-rw-r--r-- | media/libstagefright/SampleTable.cpp | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/media/libstagefright/SampleTable.cpp b/media/libstagefright/SampleTable.cpp index 1451c16..8e790fc 100644 --- a/media/libstagefright/SampleTable.cpp +++ b/media/libstagefright/SampleTable.cpp @@ -618,27 +618,26 @@ status_t SampleTable::findSyncSampleNear( } uint32_t left = 0; - while (left < mNumSyncSamples) { - uint32_t x = mSyncSamples[left]; + uint32_t right = mNumSyncSamples; + while (left < right) { + uint32_t center = left + (right - left) / 2; + uint32_t x = mSyncSamples[center]; - if (x >= start_sample_index) { + if (start_sample_index < x) { + right = center; + } else if (start_sample_index > x) { + left = center + 1; + } else { + left = center; break; } - - ++left; - } - if (left > 0) { - --left; } - uint32_t x; - if (mDataSource->readAt( - mSyncSampleOffset + 8 + left * 4, &x, 4) != 4) { - return ERROR_IO; - } + // Now ssi[left] is the sync sample index just before (or at) + // start_sample_index. + // Also start_sample_index < ssi[left + 1], if left + 1 < mNumSyncSamples. - x = ntohl(x); - --x; + uint32_t x = mSyncSamples[left]; if (left + 1 < mNumSyncSamples) { uint32_t y = mSyncSamples[left + 1]; @@ -679,15 +678,13 @@ status_t SampleTable::findSyncSampleNear( if (x > start_sample_index) { CHECK(left > 0); - if (mDataSource->readAt( - mSyncSampleOffset + 8 + (left - 1) * 4, &x, 4) != 4) { - return ERROR_IO; - } + x = mSyncSamples[left - 1]; - x = ntohl(x); - --x; - - CHECK(x <= start_sample_index); + if (x > start_sample_index) { + // The table of sync sample indices was not sorted + // properly. + return ERROR_MALFORMED; + } } break; } @@ -701,7 +698,11 @@ status_t SampleTable::findSyncSampleNear( x = mSyncSamples[left + 1]; - CHECK(x >= start_sample_index); + if (x < start_sample_index) { + // The table of sync sample indices was not sorted + // properly. + return ERROR_MALFORMED; + } } break; |