Loading media/libaaudio/tests/test_various.cpp +24 −3 Original line number Diff line number Diff line Loading @@ -75,12 +75,33 @@ void checkReleaseThenClose(aaudio_performance_mode_t perfMode, EXPECT_EQ(AAUDIO_OK, AAudioStream_requestStop(aaudioStream)); EXPECT_EQ(AAUDIO_OK, AAudioStream_release(aaudioStream)); aaudio_stream_state_t state = AAudioStream_getState(aaudioStream); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, state); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, AAudioStream_getState(aaudioStream)); // We should be able to call this again without crashing. EXPECT_EQ(AAUDIO_OK, AAudioStream_release(aaudioStream)); state = AAudioStream_getState(aaudioStream); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, AAudioStream_getState(aaudioStream)); // We expect these not to crash. AAudioStream_setBufferSizeInFrames(aaudioStream, 0); AAudioStream_setBufferSizeInFrames(aaudioStream, 99999999); // We should NOT be able to start or change a stream after it has been released. EXPECT_EQ(AAUDIO_ERROR_INVALID_STATE, AAudioStream_requestStart(aaudioStream)); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, AAudioStream_getState(aaudioStream)); EXPECT_EQ(AAUDIO_ERROR_INVALID_STATE, AAudioStream_requestPause(aaudioStream)); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, AAudioStream_getState(aaudioStream)); EXPECT_EQ(AAUDIO_ERROR_INVALID_STATE, AAudioStream_requestStop(aaudioStream)); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, AAudioStream_getState(aaudioStream)); // Does this crash? EXPECT_LT(0, AAudioStream_getFramesRead(aaudioStream)); EXPECT_LT(0, AAudioStream_getFramesWritten(aaudioStream)); // Verify Closing State. Does this crash? aaudio_stream_state_t state = AAUDIO_STREAM_STATE_UNKNOWN; EXPECT_EQ(AAUDIO_OK, AAudioStream_waitForStateChange(aaudioStream, AAUDIO_STREAM_STATE_UNKNOWN, &state, 500 * NANOS_PER_MILLISECOND)); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, state); EXPECT_EQ(AAUDIO_OK, AAudioStream_close(aaudioStream)); Loading media/libmediametrics/Android.bp +4 −2 Original line number Diff line number Diff line Loading @@ -22,9 +22,11 @@ cc_library_shared { export_include_dirs: ["include"], cflags: [ "-Werror", "-Wno-error=deprecated-declarations", "-Wall", "-Werror", "-Wextra", "-Wthread-safety", "-Wunreachable-code", ], sanitize: { Loading media/libstagefright/codecs/mp3dec/src/pvmp3_framedecoder.cpp +1 −9 Original line number Diff line number Diff line Loading @@ -659,20 +659,12 @@ void pvmp3_InitDecoder(tPVMP3DecoderExternal *pExt, huffcodetab *pHuff; pVars = (tmp3dec_file *)pMem; pVars->num_channels = 0; memset(pVars, 0, sizeof(*pVars)); pExt->totalNumberOfBitsUsed = 0; pExt->inputBufferCurrentLength = 0; pExt->inputBufferUsedLength = 0; pVars->mainDataStream.offset = 0; pv_memset((void*)pVars->mainDataBuffer, 0, BUFSIZE*sizeof(*pVars->mainDataBuffer)); pVars->inputStream.pBuffer = pExt->pInputBuffer; /* Loading media/libstagefright/id3/ID3.cpp +48 −49 Original line number Diff line number Diff line Loading @@ -107,20 +107,6 @@ ID3::ID3(DataSourceHelper *sourcehelper, bool ignoreV1, off64_t offset) } } ID3::ID3(DataSourceBase *source, bool ignoreV1, off64_t offset) : mIsValid(false), mData(NULL), mSize(0), mFirstFrameOffset(0), mVersion(ID3_UNKNOWN), mRawSize(0) { mIsValid = parseV2(source, offset); if (!mIsValid && !ignoreV1) { mIsValid = parseV1(source); } } ID3::ID3(const uint8_t *data, size_t size, bool ignoreV1) : mIsValid(false), mData(NULL), Loading Loading @@ -247,44 +233,14 @@ struct id3_header { return false; } if (header.version_major == 4) { void *copy = malloc(size); if (copy == NULL) { free(mData); mData = NULL; ALOGE("b/24623447, no more memory"); return false; } memcpy(copy, mData, size); bool success = removeUnsynchronizationV2_4(false /* iTunesHack */); if (!success) { memcpy(mData, copy, size); mSize = size; success = removeUnsynchronizationV2_4(true /* iTunesHack */); if (success) { ALOGV("Had to apply the iTunes hack to parse this ID3 tag"); } } free(copy); copy = NULL; if (!success) { free(mData); mData = NULL; return false; } } else if (header.flags & 0x80) { // first handle global unsynchronization if (header.flags & 0x80) { ALOGV("removing unsynchronization"); removeUnsynchronization(); } // handle extended header, if present mFirstFrameOffset = 0; if (header.version_major == 3 && (header.flags & 0x40)) { // Version 2.3 has an optional extended header. Loading @@ -296,6 +252,7 @@ struct id3_header { return false; } // v2.3 does not have syncsafe integers size_t extendedHeaderSize = U32_AT(&mData[0]); if (extendedHeaderSize > SIZE_MAX - 4) { free(mData); Loading Loading @@ -367,6 +324,48 @@ struct id3_header { mFirstFrameOffset = ext_size; } // Handle any v2.4 per-frame unsynchronization // The id3 spec isn't clear about what should happen if the global // unsynchronization flag is combined with per-frame unsynchronization, // or whether that's even allowed, so this code assumes id3 writing // tools do the right thing and not apply double-unsynchronization, // but will honor the flags if they are set. if (header.version_major == 4) { void *copy = malloc(size); if (copy == NULL) { free(mData); mData = NULL; ALOGE("b/24623447, no more memory"); return false; } memcpy(copy, mData, size); bool success = removeUnsynchronizationV2_4(false /* iTunesHack */); if (!success) { memcpy(mData, copy, size); mSize = size; success = removeUnsynchronizationV2_4(true /* iTunesHack */); if (success) { ALOGV("Had to apply the iTunes hack to parse this ID3 tag"); } } free(copy); copy = NULL; if (!success) { free(mData); mData = NULL; return false; } } if (header.version_major == 2) { mVersion = ID3_V2_2; } else if (header.version_major == 3) { Loading Loading @@ -411,7 +410,7 @@ static void WriteSyncsafeInteger(uint8_t *dst, size_t x) { bool ID3::removeUnsynchronizationV2_4(bool iTunesHack) { size_t oldSize = mSize; size_t offset = 0; size_t offset = mFirstFrameOffset; while (mSize >= 10 && offset <= mSize - 10) { if (!memcmp(&mData[offset], "\0\0\0\0", 4)) { break; Loading Loading @@ -445,7 +444,7 @@ bool ID3::removeUnsynchronizationV2_4(bool iTunesHack) { } if ((flags & 2) && (dataSize >= 2)) { // This file has "unsynchronization", so we have to replace occurrences // This frame has "unsynchronization", so we have to replace occurrences // of 0xff 0x00 with just 0xff in order to get the real data. size_t readOffset = offset + 11; Loading media/libstagefright/id3/test/ID3Test.cpp +11 −5 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <datasource/FileSource.h> #include <media/stagefright/foundation/hexdump.h> #include <media/MediaExtractorPluginHelper.h> #include <ID3.h> #include "ID3TestEnvironment.h" Loading @@ -42,7 +43,8 @@ TEST_P(ID3tagTest, TagTest) { string path = gEnv->getRes() + GetParam(); sp<FileSource> file = new FileSource(path.c_str()); ASSERT_EQ(file->initCheck(), (status_t)OK) << "File initialization failed! \n"; ID3 tag(file.get()); DataSourceHelper helper(file->wrap()); ID3 tag(&helper); ASSERT_TRUE(tag.isValid()) << "No valid ID3 tag found for " << path.c_str() << "\n"; ID3::Iterator it(tag, nullptr); Loading @@ -61,7 +63,8 @@ TEST_P(ID3versionTest, VersionTest) { sp<android::FileSource> file = new FileSource(path.c_str()); ASSERT_EQ(file->initCheck(), (status_t)OK) << "File initialization failed! \n"; ID3 tag(file.get()); DataSourceHelper helper(file->wrap()); ID3 tag(&helper); ASSERT_TRUE(tag.isValid()) << "No valid ID3 tag found for " << path.c_str() << "\n"; ASSERT_TRUE(tag.version() >= versionNumber) << "Expected version: " << tag.version() << " Found version: " << versionNumber; Loading @@ -73,7 +76,8 @@ TEST_P(ID3textTagTest, TextTagTest) { sp<android::FileSource> file = new FileSource(path.c_str()); ASSERT_EQ(file->initCheck(), (status_t)OK) << "File initialization failed! \n"; ID3 tag(file.get()); DataSourceHelper helper(file->wrap()); ID3 tag(&helper); ASSERT_TRUE(tag.isValid()) << "No valid ID3 tag found for " << path.c_str() << "\n"; int countTextFrames = 0; ID3::Iterator it(tag, nullptr); Loading @@ -99,7 +103,8 @@ TEST_P(ID3albumArtTest, AlbumArtTest) { sp<android::FileSource> file = new FileSource(path.c_str()); ASSERT_EQ(file->initCheck(), (status_t)OK) << "File initialization failed! \n"; ID3 tag(file.get()); DataSourceHelper helper(file->wrap()); ID3 tag(&helper); ASSERT_TRUE(tag.isValid()) << "No valid ID3 tag found for " << path.c_str() << "\n"; size_t dataSize; String8 mime; Loading @@ -124,7 +129,8 @@ TEST_P(ID3multiAlbumArtTest, MultiAlbumArtTest) { sp<android::FileSource> file = new FileSource(path.c_str()); ASSERT_EQ(file->initCheck(), (status_t)OK) << "File initialization failed! \n"; ID3 tag(file.get()); DataSourceHelper helper(file->wrap()); ID3 tag(&helper); ASSERT_TRUE(tag.isValid()) << "No valid ID3 tag found for " << path.c_str() << "\n"; int count = 0; ID3::Iterator it(tag, nullptr); Loading Loading
media/libaaudio/tests/test_various.cpp +24 −3 Original line number Diff line number Diff line Loading @@ -75,12 +75,33 @@ void checkReleaseThenClose(aaudio_performance_mode_t perfMode, EXPECT_EQ(AAUDIO_OK, AAudioStream_requestStop(aaudioStream)); EXPECT_EQ(AAUDIO_OK, AAudioStream_release(aaudioStream)); aaudio_stream_state_t state = AAudioStream_getState(aaudioStream); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, state); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, AAudioStream_getState(aaudioStream)); // We should be able to call this again without crashing. EXPECT_EQ(AAUDIO_OK, AAudioStream_release(aaudioStream)); state = AAudioStream_getState(aaudioStream); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, AAudioStream_getState(aaudioStream)); // We expect these not to crash. AAudioStream_setBufferSizeInFrames(aaudioStream, 0); AAudioStream_setBufferSizeInFrames(aaudioStream, 99999999); // We should NOT be able to start or change a stream after it has been released. EXPECT_EQ(AAUDIO_ERROR_INVALID_STATE, AAudioStream_requestStart(aaudioStream)); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, AAudioStream_getState(aaudioStream)); EXPECT_EQ(AAUDIO_ERROR_INVALID_STATE, AAudioStream_requestPause(aaudioStream)); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, AAudioStream_getState(aaudioStream)); EXPECT_EQ(AAUDIO_ERROR_INVALID_STATE, AAudioStream_requestStop(aaudioStream)); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, AAudioStream_getState(aaudioStream)); // Does this crash? EXPECT_LT(0, AAudioStream_getFramesRead(aaudioStream)); EXPECT_LT(0, AAudioStream_getFramesWritten(aaudioStream)); // Verify Closing State. Does this crash? aaudio_stream_state_t state = AAUDIO_STREAM_STATE_UNKNOWN; EXPECT_EQ(AAUDIO_OK, AAudioStream_waitForStateChange(aaudioStream, AAUDIO_STREAM_STATE_UNKNOWN, &state, 500 * NANOS_PER_MILLISECOND)); EXPECT_EQ(AAUDIO_STREAM_STATE_CLOSING, state); EXPECT_EQ(AAUDIO_OK, AAudioStream_close(aaudioStream)); Loading
media/libmediametrics/Android.bp +4 −2 Original line number Diff line number Diff line Loading @@ -22,9 +22,11 @@ cc_library_shared { export_include_dirs: ["include"], cflags: [ "-Werror", "-Wno-error=deprecated-declarations", "-Wall", "-Werror", "-Wextra", "-Wthread-safety", "-Wunreachable-code", ], sanitize: { Loading
media/libstagefright/codecs/mp3dec/src/pvmp3_framedecoder.cpp +1 −9 Original line number Diff line number Diff line Loading @@ -659,20 +659,12 @@ void pvmp3_InitDecoder(tPVMP3DecoderExternal *pExt, huffcodetab *pHuff; pVars = (tmp3dec_file *)pMem; pVars->num_channels = 0; memset(pVars, 0, sizeof(*pVars)); pExt->totalNumberOfBitsUsed = 0; pExt->inputBufferCurrentLength = 0; pExt->inputBufferUsedLength = 0; pVars->mainDataStream.offset = 0; pv_memset((void*)pVars->mainDataBuffer, 0, BUFSIZE*sizeof(*pVars->mainDataBuffer)); pVars->inputStream.pBuffer = pExt->pInputBuffer; /* Loading
media/libstagefright/id3/ID3.cpp +48 −49 Original line number Diff line number Diff line Loading @@ -107,20 +107,6 @@ ID3::ID3(DataSourceHelper *sourcehelper, bool ignoreV1, off64_t offset) } } ID3::ID3(DataSourceBase *source, bool ignoreV1, off64_t offset) : mIsValid(false), mData(NULL), mSize(0), mFirstFrameOffset(0), mVersion(ID3_UNKNOWN), mRawSize(0) { mIsValid = parseV2(source, offset); if (!mIsValid && !ignoreV1) { mIsValid = parseV1(source); } } ID3::ID3(const uint8_t *data, size_t size, bool ignoreV1) : mIsValid(false), mData(NULL), Loading Loading @@ -247,44 +233,14 @@ struct id3_header { return false; } if (header.version_major == 4) { void *copy = malloc(size); if (copy == NULL) { free(mData); mData = NULL; ALOGE("b/24623447, no more memory"); return false; } memcpy(copy, mData, size); bool success = removeUnsynchronizationV2_4(false /* iTunesHack */); if (!success) { memcpy(mData, copy, size); mSize = size; success = removeUnsynchronizationV2_4(true /* iTunesHack */); if (success) { ALOGV("Had to apply the iTunes hack to parse this ID3 tag"); } } free(copy); copy = NULL; if (!success) { free(mData); mData = NULL; return false; } } else if (header.flags & 0x80) { // first handle global unsynchronization if (header.flags & 0x80) { ALOGV("removing unsynchronization"); removeUnsynchronization(); } // handle extended header, if present mFirstFrameOffset = 0; if (header.version_major == 3 && (header.flags & 0x40)) { // Version 2.3 has an optional extended header. Loading @@ -296,6 +252,7 @@ struct id3_header { return false; } // v2.3 does not have syncsafe integers size_t extendedHeaderSize = U32_AT(&mData[0]); if (extendedHeaderSize > SIZE_MAX - 4) { free(mData); Loading Loading @@ -367,6 +324,48 @@ struct id3_header { mFirstFrameOffset = ext_size; } // Handle any v2.4 per-frame unsynchronization // The id3 spec isn't clear about what should happen if the global // unsynchronization flag is combined with per-frame unsynchronization, // or whether that's even allowed, so this code assumes id3 writing // tools do the right thing and not apply double-unsynchronization, // but will honor the flags if they are set. if (header.version_major == 4) { void *copy = malloc(size); if (copy == NULL) { free(mData); mData = NULL; ALOGE("b/24623447, no more memory"); return false; } memcpy(copy, mData, size); bool success = removeUnsynchronizationV2_4(false /* iTunesHack */); if (!success) { memcpy(mData, copy, size); mSize = size; success = removeUnsynchronizationV2_4(true /* iTunesHack */); if (success) { ALOGV("Had to apply the iTunes hack to parse this ID3 tag"); } } free(copy); copy = NULL; if (!success) { free(mData); mData = NULL; return false; } } if (header.version_major == 2) { mVersion = ID3_V2_2; } else if (header.version_major == 3) { Loading Loading @@ -411,7 +410,7 @@ static void WriteSyncsafeInteger(uint8_t *dst, size_t x) { bool ID3::removeUnsynchronizationV2_4(bool iTunesHack) { size_t oldSize = mSize; size_t offset = 0; size_t offset = mFirstFrameOffset; while (mSize >= 10 && offset <= mSize - 10) { if (!memcmp(&mData[offset], "\0\0\0\0", 4)) { break; Loading Loading @@ -445,7 +444,7 @@ bool ID3::removeUnsynchronizationV2_4(bool iTunesHack) { } if ((flags & 2) && (dataSize >= 2)) { // This file has "unsynchronization", so we have to replace occurrences // This frame has "unsynchronization", so we have to replace occurrences // of 0xff 0x00 with just 0xff in order to get the real data. size_t readOffset = offset + 11; Loading
media/libstagefright/id3/test/ID3Test.cpp +11 −5 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <datasource/FileSource.h> #include <media/stagefright/foundation/hexdump.h> #include <media/MediaExtractorPluginHelper.h> #include <ID3.h> #include "ID3TestEnvironment.h" Loading @@ -42,7 +43,8 @@ TEST_P(ID3tagTest, TagTest) { string path = gEnv->getRes() + GetParam(); sp<FileSource> file = new FileSource(path.c_str()); ASSERT_EQ(file->initCheck(), (status_t)OK) << "File initialization failed! \n"; ID3 tag(file.get()); DataSourceHelper helper(file->wrap()); ID3 tag(&helper); ASSERT_TRUE(tag.isValid()) << "No valid ID3 tag found for " << path.c_str() << "\n"; ID3::Iterator it(tag, nullptr); Loading @@ -61,7 +63,8 @@ TEST_P(ID3versionTest, VersionTest) { sp<android::FileSource> file = new FileSource(path.c_str()); ASSERT_EQ(file->initCheck(), (status_t)OK) << "File initialization failed! \n"; ID3 tag(file.get()); DataSourceHelper helper(file->wrap()); ID3 tag(&helper); ASSERT_TRUE(tag.isValid()) << "No valid ID3 tag found for " << path.c_str() << "\n"; ASSERT_TRUE(tag.version() >= versionNumber) << "Expected version: " << tag.version() << " Found version: " << versionNumber; Loading @@ -73,7 +76,8 @@ TEST_P(ID3textTagTest, TextTagTest) { sp<android::FileSource> file = new FileSource(path.c_str()); ASSERT_EQ(file->initCheck(), (status_t)OK) << "File initialization failed! \n"; ID3 tag(file.get()); DataSourceHelper helper(file->wrap()); ID3 tag(&helper); ASSERT_TRUE(tag.isValid()) << "No valid ID3 tag found for " << path.c_str() << "\n"; int countTextFrames = 0; ID3::Iterator it(tag, nullptr); Loading @@ -99,7 +103,8 @@ TEST_P(ID3albumArtTest, AlbumArtTest) { sp<android::FileSource> file = new FileSource(path.c_str()); ASSERT_EQ(file->initCheck(), (status_t)OK) << "File initialization failed! \n"; ID3 tag(file.get()); DataSourceHelper helper(file->wrap()); ID3 tag(&helper); ASSERT_TRUE(tag.isValid()) << "No valid ID3 tag found for " << path.c_str() << "\n"; size_t dataSize; String8 mime; Loading @@ -124,7 +129,8 @@ TEST_P(ID3multiAlbumArtTest, MultiAlbumArtTest) { sp<android::FileSource> file = new FileSource(path.c_str()); ASSERT_EQ(file->initCheck(), (status_t)OK) << "File initialization failed! \n"; ID3 tag(file.get()); DataSourceHelper helper(file->wrap()); ID3 tag(&helper); ASSERT_TRUE(tag.isValid()) << "No valid ID3 tag found for " << path.c_str() << "\n"; int count = 0; ID3::Iterator it(tag, nullptr); Loading