diff options
author | Wei Jia <wjia@google.com> | 2015-08-21 19:57:30 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-08-21 19:57:30 +0000 |
commit | f814f84e09191af23bbf8d307f02704e20cc887c (patch) | |
tree | db92ff44d1d3c45e05b96db5b2f49942cf0c359e | |
parent | ca095ac251ad02ad745d763f37ec3fcc5a8aa2ea (diff) | |
parent | d8816a13dbcafd5d61d26a8a6b2e892452bca1a7 (diff) | |
download | frameworks_av-f814f84e09191af23bbf8d307f02704e20cc887c.zip frameworks_av-f814f84e09191af23bbf8d307f02704e20cc887c.tar.gz frameworks_av-f814f84e09191af23bbf8d307f02704e20cc887c.tar.bz2 |
am d8816a13: DO NOT MERGE libstagefright: Fix crash in convertMetaDataToMessage
* commit 'd8816a13dbcafd5d61d26a8a6b2e892452bca1a7':
DO NOT MERGE libstagefright: Fix crash in convertMetaDataToMessage
-rw-r--r-- | media/libstagefright/Utils.cpp | 66 |
1 files changed, 51 insertions, 15 deletions
diff --git a/media/libstagefright/Utils.cpp b/media/libstagefright/Utils.cpp index 216a329..80d8cef 100644 --- a/media/libstagefright/Utils.cpp +++ b/media/libstagefright/Utils.cpp @@ -68,6 +68,23 @@ uint64_t hton64(uint64_t x) { return ((uint64_t)htonl(x & 0xffffffff) << 32) | htonl(x >> 32); } +static status_t copyNALUToABuffer(sp<ABuffer> *buffer, const uint8_t *ptr, size_t length) { + if (((*buffer)->size() + 4 + length) > ((*buffer)->capacity() - (*buffer)->offset())) { + sp<ABuffer> tmpBuffer = new (std::nothrow) ABuffer((*buffer)->size() + 4 + length + 1024); + if (tmpBuffer.get() == NULL || tmpBuffer->base() == NULL) { + return NO_MEMORY; + } + memcpy(tmpBuffer->data(), (*buffer)->data(), (*buffer)->size()); + tmpBuffer->setRange(0, (*buffer)->size()); + (*buffer) = tmpBuffer; + } + + memcpy((*buffer)->data() + (*buffer)->size(), "\x00\x00\x00\x01", 4); + memcpy((*buffer)->data() + (*buffer)->size() + 4, ptr, length); + (*buffer)->setRange((*buffer)->offset(), (*buffer)->size() + 4 + length); + return OK; +} + status_t convertMetaDataToMessage( const sp<MetaData> &meta, sp<AMessage> *format) { format->clear(); @@ -163,7 +180,10 @@ status_t convertMetaDataToMessage( ptr += 6; size -= 6; - sp<ABuffer> buffer = new ABuffer(1024); + sp<ABuffer> buffer = new (std::nothrow) ABuffer(1024); + if (buffer.get() == NULL || buffer->base() == NULL) { + return NO_MEMORY; + } buffer->setRange(0, 0); for (size_t i = 0; i < numSeqParameterSets; ++i) { @@ -173,11 +193,13 @@ status_t convertMetaDataToMessage( ptr += 2; size -= 2; - CHECK(size >= length); - - memcpy(buffer->data() + buffer->size(), "\x00\x00\x00\x01", 4); - memcpy(buffer->data() + buffer->size() + 4, ptr, length); - buffer->setRange(0, buffer->size() + 4 + length); + if (size < length) { + return BAD_VALUE; + } + status_t err = copyNALUToABuffer(&buffer, ptr, length); + if (err != OK) { + return err; + } ptr += length; size -= length; @@ -188,7 +210,10 @@ status_t convertMetaDataToMessage( msg->setBuffer("csd-0", buffer); - buffer = new ABuffer(1024); + buffer = new (std::nothrow) ABuffer(1024); + if (buffer.get() == NULL || buffer->base() == NULL) { + return NO_MEMORY; + } buffer->setRange(0, 0); CHECK(size >= 1); @@ -203,11 +228,13 @@ status_t convertMetaDataToMessage( ptr += 2; size -= 2; - CHECK(size >= length); - - memcpy(buffer->data() + buffer->size(), "\x00\x00\x00\x01", 4); - memcpy(buffer->data() + buffer->size() + 4, ptr, length); - buffer->setRange(0, buffer->size() + 4 + length); + if (size < length) { + return BAD_VALUE; + } + status_t err = copyNALUToABuffer(&buffer, ptr, length); + if (err != OK) { + return err; + } ptr += length; size -= length; @@ -225,7 +252,10 @@ status_t convertMetaDataToMessage( esds.getCodecSpecificInfo( &codec_specific_data, &codec_specific_data_size); - sp<ABuffer> buffer = new ABuffer(codec_specific_data_size); + sp<ABuffer> buffer = new (std::nothrow) ABuffer(codec_specific_data_size); + if (buffer.get() == NULL || buffer->base() == NULL) { + return NO_MEMORY; + } memcpy(buffer->data(), codec_specific_data, codec_specific_data_size); @@ -234,7 +264,10 @@ status_t convertMetaDataToMessage( buffer->meta()->setInt64("timeUs", 0); msg->setBuffer("csd-0", buffer); } else if (meta->findData(kKeyVorbisInfo, &type, &data, &size)) { - sp<ABuffer> buffer = new ABuffer(size); + sp<ABuffer> buffer = new (std::nothrow) ABuffer(size); + if (buffer.get() == NULL || buffer->base() == NULL) { + return NO_MEMORY; + } memcpy(buffer->data(), data, size); buffer->meta()->setInt32("csd", true); @@ -245,7 +278,10 @@ status_t convertMetaDataToMessage( return -EINVAL; } - buffer = new ABuffer(size); + buffer = new (std::nothrow) ABuffer(size); + if (buffer.get() == NULL || buffer->base() == NULL) { + return NO_MEMORY; + } memcpy(buffer->data(), data, size); buffer->meta()->setInt32("csd", true); |