Index: base/pickle.cc |
diff --git a/base/pickle.cc b/base/pickle.cc |
index b12ec9a53e8f31e6c8443fba51e5139392f41ee5..ba78c4ba33bb2d3b319b150fdef42d504c138996 100644 |
--- a/base/pickle.cc |
+++ b/base/pickle.cc |
@@ -11,6 +11,7 @@ |
#include "base/bits.h" |
#include "base/macros.h" |
+#include "base/numerics/safe_conversions.h" |
#include "build/build_config.h" |
namespace base { |
@@ -84,12 +85,20 @@ bool PickleIterator::ReadBool(bool* result) { |
return ReadBuiltinType(result); |
} |
-bool PickleIterator::ReadInt(int* result) { |
+bool PickleIterator::ReadInt(int* result) { |
return ReadBuiltinType(result); |
} |
bool PickleIterator::ReadLong(long* result) { |
- return ReadBuiltinType(result); |
+ // Always read long as a 64-bit value to ensure compatibility between 32-bit |
+ // and 64-bit processes. |
+ int64_t result_int64 = 0; |
+ if (!ReadBuiltinType(&result_int64)) |
+ return false; |
+ // CHECK if the cast truncates the value so that we know to change this IPC |
+ // parameter to use int64_t. |
+ *result = base::checked_cast<long>(result_int64); |
+ return true; |
} |
bool PickleIterator::ReadUInt16(uint16_t* result) { |
@@ -108,16 +117,6 @@ bool PickleIterator::ReadUInt64(uint64_t* result) { |
return ReadBuiltinType(result); |
} |
-bool PickleIterator::ReadSizeT(size_t* result) { |
- // Always read size_t as a 64-bit value to ensure compatibility between 32-bit |
- // and 64-bit processes. |
- uint64_t result_uint64 = 0; |
- bool success = ReadBuiltinType(&result_uint64); |
- *result = static_cast<size_t>(result_uint64); |
- // Fail if the cast above truncates the value. |
- return success && (*result == result_uint64); |
-} |
- |
bool PickleIterator::ReadFloat(float* result) { |
// crbug.com/315213 |
// The source data may not be properly aligned, and unaligned float reads |