Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Unified Diff: base/pickle.cc

Issue 1619363002: Add compile time checks against longs being used in IPC structs on 32 bit Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | ipc/ipc_message_utils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698