Merge changes I6b9963d0,Ia4537f5b,I9e018974
* changes:
Enable integer overflow detection in libmedia
Fix benign overflow in ClientProxy::getMisalignment
Fix benign unsigned overflow in AudioTrack
diff --git a/media/libmedia/Android.mk b/media/libmedia/Android.mk
index 6c585fb..9965ca8 100644
--- a/media/libmedia/Android.mk
+++ b/media/libmedia/Android.mk
@@ -83,6 +83,9 @@
$(call include-path-for, audio-effects) \
$(call include-path-for, audio-utils)
+LOCAL_CLANG := true
+LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow
+
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 735db5c..4a79bef 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -2018,9 +2018,9 @@
// 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
diff --git a/media/libmedia/AudioTrackShared.cpp b/media/libmedia/AudioTrackShared.cpp
index ff24475..7c7c03a 100644
--- a/media/libmedia/AudioTrackShared.cpp
+++ b/media/libmedia/AudioTrackShared.cpp
@@ -324,6 +324,7 @@
}
}
+__attribute__((no_sanitize("integer")))
size_t ClientProxy::getMisalignment()
{
audio_track_cblk_t* cblk = mCblk;