diff options
author | Chad Brubaker <cbrubaker@google.com> | 2015-09-23 15:17:29 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-12-07 18:45:16 -0800 |
commit | 6179f6448ab910b1d2d7ccfa91152a792efc740a (patch) | |
tree | 5773b29b9c6ce5f5e6192390749d828060527f07 /media/libmedia | |
parent | c3e8884de570d95be251f7e04c60fb55428c7260 (diff) | |
download | frameworks_av-6179f6448ab910b1d2d7ccfa91152a792efc740a.zip frameworks_av-6179f6448ab910b1d2d7ccfa91152a792efc740a.tar.gz frameworks_av-6179f6448ab910b1d2d7ccfa91152a792efc740a.tar.bz2 |
Fix benign overflow in AudioTrack
two uint32_t's were being used in a computation that could be negative,
cast to int32_t before the subtraction to prevent incorrect overflow
detection.
Change-Id: I33c5ef79a0ebbba055daa0ea041b42229d0c3152
Diffstat (limited to 'media/libmedia')
-rw-r--r-- | media/libmedia/AudioTrack.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp index b969449..39536a2 100644 --- a/media/libmedia/AudioTrack.cpp +++ b/media/libmedia/AudioTrack.cpp @@ -2197,8 +2197,7 @@ uint32_t AudioTrack::updateAndGetPosition_l() { // This is the sole place to read server consumed frames uint32_t newServer = mProxy->getPosition(); - int32_t delta = newServer - mServer; - mServer = newServer; + uint32_t delta = newServer > mServer ? newServer - mServer : 0; // TODO There is controversy about whether there can be "negative jitter" in server position. // This should be investigated further, and if possible, it should be addressed. // A more definite failure mode is infrequent polling by client. @@ -2207,11 +2206,12 @@ uint32_t AudioTrack::updateAndGetPosition_l() // That should ensure delta never goes negative for infrequent polling // unless the server has more than 2^31 frames in its buffer, // in which case the use of uint32_t for these counters has bigger issues. - if (delta < 0) { - ALOGE("detected illegal retrograde motion by the server: mServer advanced by %d", delta); - delta = 0; + if (newServer < mServer) { + ALOGE("detected illegal retrograde motion by the server: mServer advanced by %d", + (int32_t) newServer - mServer); } - return mPosition += (uint32_t) delta; + mServer = newServer; + return mPosition += delta; } bool AudioTrack::isSampleRateSpeedAllowed_l(uint32_t sampleRate, float speed) const |