reject sizes that will overflow in SkSpan

Change-Id: Ie1eac40fe678529410f3ae4ab0cc7460dedfa4c2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/408296
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/include/core/SkSpan.h b/include/core/SkSpan.h
index 5e1ad5b..b09ec867 100644
--- a/include/core/SkSpan.h
+++ b/include/core/SkSpan.h
@@ -26,7 +26,9 @@
 class SkSpan {
 public:
     constexpr SkSpan() : fPtr{nullptr}, fSize{0} {}
-    constexpr SkSpan(T* ptr, size_t size) : fPtr{ptr}, fSize{size} {}
+    constexpr SkSpan(T* ptr, size_t size) : fPtr{ptr}, fSize{size} {
+        SkASSERT(size < kMaxSize);
+    }
     template <typename U, typename = typename std::enable_if<std::is_same<const U, T>::value>::type>
     constexpr SkSpan(const SkSpan<U>& that) : fPtr(that.data()), fSize{that.size()} {}
     constexpr SkSpan(const SkSpan& o) = default;
@@ -65,6 +67,7 @@
     }
 
 private:
+    static constexpr size_t kMaxSize = std::numeric_limits<size_t>::max() / sizeof(T);
     T* fPtr;
     size_t fSize;
 };