Skip to content

Commit 17e982c

Browse files
marconeandi34
authored andcommitted
Make VBRISeeker more robust
Bug: 32577290 Change-Id: I9bcc9422ae7dd3ae4a38df330c9dcd7ac4941ec8 (cherry picked from commit 7fdd364)
1 parent b40f599 commit 17e982c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

media/libstagefright/VBRISeeker.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,23 @@ sp<VBRISeeker> VBRISeeker::CreateFromSource(
8080
scale,
8181
entrySize);
8282

83+
if (entrySize > 4) {
84+
ALOGE("invalid VBRI entry size: %zu", entrySize);
85+
return NULL;
86+
}
87+
88+
sp<VBRISeeker> seeker = new (std::nothrow) VBRISeeker;
89+
if (seeker == NULL) {
90+
ALOGW("Couldn't allocate VBRISeeker");
91+
return NULL;
92+
}
93+
8394
size_t totalEntrySize = numEntries * entrySize;
84-
uint8_t *buffer = new uint8_t[totalEntrySize];
95+
uint8_t *buffer = new (std::nothrow) uint8_t[totalEntrySize];
96+
if (!buffer) {
97+
ALOGW("Couldn't allocate %zu bytes", totalEntrySize);
98+
return NULL;
99+
}
85100

86101
n = source->readAt(pos + sizeof(vbriHeader), buffer, totalEntrySize);
87102
if (n < (ssize_t)totalEntrySize) {
@@ -91,7 +106,6 @@ sp<VBRISeeker> VBRISeeker::CreateFromSource(
91106
return NULL;
92107
}
93108

94-
sp<VBRISeeker> seeker = new VBRISeeker;
95109
seeker->mBasePos = post_id3_pos + frameSize;
96110
// only update mDurationUs if the calculated duration is valid (non zero)
97111
// otherwise, leave duration at -1 so that getDuration() and getOffsetForTime()

0 commit comments

Comments
 (0)