Index: mojo/public/cpp/bindings/lib/validation_util.h |
diff --git a/mojo/public/cpp/bindings/lib/validation_util.h b/mojo/public/cpp/bindings/lib/validation_util.h |
index c883392ebc13fae00fd7e629644a5bca880556ae..1c6c53cb23eba61f6139a66e712ba6055d5628b9 100644 |
--- a/mojo/public/cpp/bindings/lib/validation_util.h |
+++ b/mojo/public/cpp/bindings/lib/validation_util.h |
@@ -19,7 +19,15 @@ namespace internal { |
// Checks whether decoding the pointer will overflow and produce a pointer |
// smaller than |offset|. |
-bool ValidateEncodedPointer(const uint64_t* offset); |
+inline bool ValidateEncodedPointer(const uint64_t* offset) { |
+ // - Make sure |*offset| is no more than 32-bits. |
+ // - Cast |offset| to uintptr_t so overflow behavior is well defined across |
+ // 32-bit and 64-bit systems. |
+ return *offset <= std::numeric_limits<uint32_t>::max() && |
+ (reinterpret_cast<uintptr_t>(offset) + |
+ static_cast<uint32_t>(*offset) >= |
+ reinterpret_cast<uintptr_t>(offset)); |
+} |
template <typename T> |
bool ValidatePointer(const Pointer<T>& input, |