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

Side by Side Diff: ipc/ipc_message.cc

Issue 1308613006: ipc: Update Message::FindNext to parse brokered attachments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Really disable tests. Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ipc/ipc_message.h" 5 #include "ipc/ipc_message.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "ipc/ipc_message_attachment.h" 10 #include "ipc/ipc_message_attachment.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 const char* data = end_of_payload(); 126 const char* data = end_of_payload();
127 data -= sizeof(int64); 127 data -= sizeof(int64);
128 return *(reinterpret_cast<const int64*>(data)); 128 return *(reinterpret_cast<const int64*>(data));
129 } 129 }
130 130
131 void Message::set_received_time(int64 time) const { 131 void Message::set_received_time(int64 time) const {
132 received_time_ = time; 132 received_time_ = time;
133 } 133 }
134 #endif 134 #endif
135 135
136 Message::NextMessageInfo::NextMessageInfo()
137 : message_found(false),
138 parsing_error(false),
139 pickle_end(nullptr),
140 message_end(nullptr) {}
141 Message::NextMessageInfo::~NextMessageInfo() {}
142
143 // static
144 Message::NextMessageInfo Message::FindNext(const char* range_start,
145 const char* range_end) {
146 NextMessageInfo info;
147 const char* pickle_end =
148 base::Pickle::FindNext(sizeof(Header), range_start, range_end);
149 if (pickle_end == nullptr)
Tom Sepez 2015/09/01 18:01:54 nit: if (!pickle_end)
erikchen 2015/09/04 02:13:39 Done.
150 return info;
151 info.pickle_end = pickle_end;
152
153 #if USE_ATTACHMENT_BROKER
154 // The data is not copied.
155 size_t pickle_len = static_cast<size_t>(pickle_end - range_start);
156 Message message(range_start, static_cast<int>(pickle_len));
157 int num_attachments = message.header()->num_brokered_attachments;
158
159 // Each brokered attachment adds kNonceSize bytes of data to the message. We
160 // want to avoid overflows in our computations, so we limit the number of
161 // brokerable attachments to 100.
162 if (num_attachments > 100) {
Tom Sepez 2015/09/01 18:01:54 nit: this should be a constant kSomethingOrOther i
erikchen 2015/09/04 02:13:39 The previous code didn't actually prevent overflow
163 info.parsing_error = true;
164 return info;
165 }
166
167 // Check whether the range includes the attachments.
168 size_t attachment_length = num_attachments * BrokerableAttachment::kNonceSize;
169 size_t buffer_length = static_cast<size_t>(range_end - range_start);
170 if (buffer_length < attachment_length + pickle_len)
171 return info;
172
173 for (int i = 0; i < num_attachments; ++i) {
174 const char* attachment_start =
175 pickle_end + i * (BrokerableAttachment::kNonceSize);
Tom Sepez 2015/09/01 18:01:54 nit: unnecessary ()
erikchen 2015/09/04 02:13:39 removed
176 BrokerableAttachment::AttachmentId id(attachment_start,
177 BrokerableAttachment::kNonceSize);
178 info.attachment_ids.push_back(id);
179 }
180 info.message_end =
181 pickle_end + num_attachments * BrokerableAttachment::kNonceSize;
182 #else
183 info.message_end = pickle_end;
184 #endif // USE_ATTACHMENT_BROKER
185
186 info.message_found = true;
187 return info;
188 }
189
136 bool Message::WriteAttachment(scoped_refptr<MessageAttachment> attachment) { 190 bool Message::WriteAttachment(scoped_refptr<MessageAttachment> attachment) {
137 // We write the index of the descriptor so that we don't have to 191 // We write the index of the descriptor so that we don't have to
138 // keep the current descriptor as extra decoding state when deserialising. 192 // keep the current descriptor as extra decoding state when deserialising.
139 WriteInt(attachment_set()->size()); 193 WriteInt(attachment_set()->size());
140 194
141 #if USE_ATTACHMENT_BROKER 195 #if USE_ATTACHMENT_BROKER
142 if (attachment->GetType() == MessageAttachment::TYPE_BROKERABLE_ATTACHMENT) 196 if (attachment->GetType() == MessageAttachment::TYPE_BROKERABLE_ATTACHMENT)
143 header()->num_brokered_attachments += 1; 197 header()->num_brokered_attachments += 1;
144 #endif 198 #endif
145 199
(...skipping 22 matching lines...) Expand all
168 bool Message::HasMojoHandles() const { 222 bool Message::HasMojoHandles() const {
169 return attachment_set_.get() && attachment_set_->num_mojo_handles() > 0; 223 return attachment_set_.get() && attachment_set_->num_mojo_handles() > 0;
170 } 224 }
171 225
172 bool Message::HasBrokerableAttachments() const { 226 bool Message::HasBrokerableAttachments() const {
173 return attachment_set_.get() && 227 return attachment_set_.get() &&
174 attachment_set_->num_brokerable_attachments() > 0; 228 attachment_set_->num_brokerable_attachments() > 0;
175 } 229 }
176 230
177 } // namespace IPC 231 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698