Index: base/pickle.cc |
diff --git a/base/pickle.cc b/base/pickle.cc |
index d83391bb524194b212a1f86ea0da26c1befd84ea..9447c806fac0a988b66d023626c4cf3714901d98 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 { |
@@ -89,7 +90,15 @@ bool PickleIterator::ReadInt(int* 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); |
Tom Sepez
2016/01/27 18:23:20
Maybe we return FALSE if the value is too big to f
jam
2016/01/27 18:42:55
good question: i wanted to avoid this because it l
|
+ return true; |
} |
bool PickleIterator::ReadUInt16(uint16_t* result) { |
@@ -112,10 +121,12 @@ 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); |
+ if (!ReadBuiltinType(&result_uint64)) |
+ return false; |
+ // CHECK if the cast truncates the value so that we know to change this IPC |
+ // parameter to use uint64_t. |
Tom Sepez
2016/01/27 18:23:20
Same here.
|
+ *result = base::checked_cast<size_t>(result_uint64); |
+ return true; |
} |
bool PickleIterator::ReadFloat(float* result) { |