diff options
author | Lajos Molnar <lajos@google.com> | 2015-04-01 19:32:25 -0700 |
---|---|---|
committer | Lajos Molnar <lajos@google.com> | 2015-04-24 17:10:41 -0700 |
commit | bfed843041b6aaec13ee19996748a7a1476db9c8 (patch) | |
tree | f6f6744dbf809a6d7897767f264944922fe954cf /include | |
parent | eb204f82afd5519eb544bf8bee692e7152820c3b (diff) | |
download | frameworks_av-bfed843041b6aaec13ee19996748a7a1476db9c8.zip frameworks_av-bfed843041b6aaec13ee19996748a7a1476db9c8.tar.gz frameworks_av-bfed843041b6aaec13ee19996748a7a1476db9c8.tar.bz2 |
Add AUtils::isInRange, and use it to detect malformed MPEG4 nal sizes
Bug: 19641538
Change-Id: I5aae3f100846c125decc61eec7cd6563e3f33777
Diffstat (limited to 'include')
-rw-r--r-- | include/media/stagefright/foundation/AUtils.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/media/stagefright/foundation/AUtils.h b/include/media/stagefright/foundation/AUtils.h index 3a73a39..255bcbe 100644 --- a/include/media/stagefright/foundation/AUtils.h +++ b/include/media/stagefright/foundation/AUtils.h @@ -55,6 +55,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) { |