summaryrefslogtreecommitdiffstats
path: root/media/libmedia
diff options
context:
space:
mode:
authorChad Brubaker <cbrubaker@google.com>2015-09-22 14:11:35 -0700
committerSteve Kondik <steve@cyngn.com>2015-12-07 18:45:16 -0800
commitc0bad787f59f9b3c4a15819461867a7997e6d5e3 (patch)
treef9530a5db9dfb8f0622bcee96c185115fe5a6234 /media/libmedia
parent6179f6448ab910b1d2d7ccfa91152a792efc740a (diff)
downloadframeworks_av-c0bad787f59f9b3c4a15819461867a7997e6d5e3.zip
frameworks_av-c0bad787f59f9b3c4a15819461867a7997e6d5e3.tar.gz
frameworks_av-c0bad787f59f9b3c4a15819461867a7997e6d5e3.tar.bz2
Fix benign unsigned overflow in AudioTrack
An unsigned overflow could occur in timestamp computation when mTimestamp < mServer. Change-Id: I9e01897478a6d481dd6fb7303d325617466497cf
Diffstat (limited to 'media/libmedia')
-rw-r--r--media/libmedia/AudioTrack.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 39536a2..8c47268 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -2364,9 +2364,9 @@ status_t AudioTrack::getTimestamp(AudioTimestamp& timestamp)
// Convert timestamp position from server time base to client time base.
// TODO The following code should work OK now because timestamp.mPosition is 32-bit.
// But if we change it to 64-bit then this could fail.
- // If (mPosition - mServer) can be negative then should use:
- // (int32_t)(mPosition - mServer)
- timestamp.mPosition += mPosition - mServer;
+ // Split this out instead of using += to prevent unsigned overflow
+ // checks in the outer sum.
+ timestamp.mPosition = timestamp.mPosition + static_cast<int32_t>(mPosition) - mServer;
// Immediately after a call to getPosition_l(), mPosition and
// mServer both represent the same frame position. mPosition is
// in client's point of view, and mServer is in server's point of