summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLajos Molnar <lajos@google.com>2015-05-12 22:14:58 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-05-12 22:14:58 +0000
commitbcf2becf206b5d56c89bf2b43356fd7995003302 (patch)
tree0fa5c016138944033cdfe35b821853499541dc56 /include
parent07e80f7a2da0a28d977adfb0372fdf385f964bc7 (diff)
parentc531d9956513b9b82dad84aeb507b866e6b3951a (diff)
downloadframeworks_av-bcf2becf206b5d56c89bf2b43356fd7995003302.zip
frameworks_av-bcf2becf206b5d56c89bf2b43356fd7995003302.tar.gz
frameworks_av-bcf2becf206b5d56c89bf2b43356fd7995003302.tar.bz2
am c531d995: am 438217a0: Merge "Add AUtils::isInRange, and use it to detect malformed MPEG4 nal sizes" into lmp-dev
* commit 'c531d9956513b9b82dad84aeb507b866e6b3951a': Add AUtils::isInRange, and use it to detect malformed MPEG4 nal sizes
Diffstat (limited to 'include')
-rw-r--r--include/media/stagefright/foundation/AUtils.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/media/stagefright/foundation/AUtils.h b/include/media/stagefright/foundation/AUtils.h
index d7ecf50..47444c1 100644
--- a/include/media/stagefright/foundation/AUtils.h
+++ b/include/media/stagefright/foundation/AUtils.h
@@ -61,6 +61,28 @@ inline static const T &max(const T &a, const T &b) {
return a > b ? a : b;
}
+template<class T>
+void ENSURE_UNSIGNED_TYPE() {
+ T TYPE_MUST_BE_UNSIGNED[(T)-1 < 0 ? -1 : 0] __unused;
+}
+
+// needle is in range [hayStart, hayStart + haySize)
+template<class T, class U>
+inline static bool isInRange(const T &hayStart, const U &haySize, const T &needle) {
+ ENSURE_UNSIGNED_TYPE<U>();
+ return (T)(hayStart + haySize) >= hayStart && needle >= hayStart && (U)(needle - hayStart) < haySize;
+}
+
+// [needleStart, needleStart + needleSize) is in range [hayStart, hayStart + haySize)
+template<class T, class U>
+inline static bool isInRange(
+ const T &hayStart, const U &haySize, const T &needleStart, const U &needleSize) {
+ ENSURE_UNSIGNED_TYPE<U>();
+ return isInRange(hayStart, haySize, needleStart)
+ && (T)(needleStart + needleSize) >= needleStart
+ && (U)(needleStart + needleSize - hayStart) <= haySize;
+}
+
/* T must be integer type, period must be positive */
template<class T>
inline static T periodicError(const T &val, const T &period) {