summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLajos Molnar <lajos@google.com>2015-05-12 22:55:01 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-05-12 22:55:01 +0000
commit0eb7c79398ef04e457c76f117feef6d7bcbbc684 (patch)
treef4858d5db5415c19ca25f3e8899f880307b3b6a5 /include
parenta4b4ca508827cc85db9708307243886024f298bc (diff)
parentb5fbb81157eaab594bb37275176a0a178098dc46 (diff)
downloadframeworks_av-0eb7c79398ef04e457c76f117feef6d7bcbbc684.zip
frameworks_av-0eb7c79398ef04e457c76f117feef6d7bcbbc684.tar.gz
frameworks_av-0eb7c79398ef04e457c76f117feef6d7bcbbc684.tar.bz2
am b5fbb811: am c8c86c1d: am bcf2becf: am c531d995: am 438217a0: Merge "Add AUtils::isInRange, and use it to detect malformed MPEG4 nal sizes" into lmp-dev
* commit 'b5fbb81157eaab594bb37275176a0a178098dc46': 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) {