Use base::checked_cast to convert uint64_t to size_t

Do the same thing as http://crrev.com/c/5213529

BUG=b:324173685
TEST=cros_run_unit_tests --board=hana --packages cbor

Change-Id: I22b877d314f6f0af9b67d7fb87211311bcdb5a44
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/cbor/+/5274069
Reviewed-by: Tom Hughes <[email protected]>
Commit-Queue: Ryo Hashimoto <[email protected]>
Tested-by: Ryo Hashimoto <[email protected]>
diff --git a/reader.cc b/reader.cc
index 03c0995..b4a77e1 100644
--- a/reader.cc
+++ b/reader.cc
@@ -367,8 +367,14 @@
     error_code_ = DecoderError::INCOMPLETE_CBOR_DATA;
     return std::nullopt;
   }
-  const base::span<const uint8_t> ret = rest_.first(num_bytes);
-  rest_ = rest_.subspan(num_bytes);
+
+  // The `uint64_t` => `size_t` conversion below will always succeed
+  // because the `if` condition above implies that `num_bytes` fits into a
+  // `size_t`.
+  size_t size = base::checked_cast<size_t>(num_bytes);
+
+  const base::span<const uint8_t> ret = rest_.first(size);
+  rest_ = rest_.subspan(size);
   return ret;
 }