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

Side by Side Diff: content/public/common/common_param_traits.cc

Issue 11617006: Add some bounds for gfx ipc deserialization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « content/common/cc_messages_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/public/common/common_param_traits.h" 5 #include "content/public/common/common_param_traits.h"
6 6
7 #include <limits>
8
7 #include "content/public/common/content_constants.h" 9 #include "content/public/common/content_constants.h"
8 #include "content/public/common/referrer.h" 10 #include "content/public/common/referrer.h"
9 #include "net/base/host_port_pair.h" 11 #include "net/base/host_port_pair.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "ui/gfx/rect.h" 13 #include "ui/gfx/rect.h"
12 #include "ui/gfx/rect_f.h" 14 #include "ui/gfx/rect_f.h"
13 15
14 namespace { 16 namespace {
15 17
16 struct SkBitmap_Data { 18 struct SkBitmap_Data {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 return false; 163 return false;
162 r->set_x(x); 164 r->set_x(x);
163 r->set_y(y); 165 r->set_y(y);
164 return true; 166 return true;
165 } 167 }
166 168
167 void ParamTraits<gfx::PointF>::Log(const gfx::PointF& v, std::string* l) { 169 void ParamTraits<gfx::PointF>::Log(const gfx::PointF& v, std::string* l) {
168 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); 170 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y()));
169 } 171 }
170 172
171 void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) { 173 void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) {
piman 2013/01/07 19:05:56 could we add a DCHECK that the serialized values p
jschuh 2013/01/07 22:24:14 Yep.
172 m->WriteInt(p.width()); 174 m->WriteInt(p.width());
173 m->WriteInt(p.height()); 175 m->WriteInt(p.height());
174 } 176 }
175 177
176 bool ParamTraits<gfx::Size>::Read(const Message* m, 178 bool ParamTraits<gfx::Size>::Read(const Message* m,
177 PickleIterator* iter, 179 PickleIterator* iter,
178 gfx::Size* r) { 180 gfx::Size* r) {
179 int w, h; 181 int w, h;
180 if (!m->ReadInt(iter, &w) || 182 if (!m->ReadInt(iter, &w) || w < 0 ||
181 !m->ReadInt(iter, &h)) 183 !m->ReadInt(iter, &h) || h < 0 ||
184 (h && w > ((std::numeric_limits<int>::max() / 4) / h)))
danakj 2013/01/07 19:19:03 We already DCHECK that sizes have positive values
danakj 2013/01/07 19:21:52 Actually maybe we don't. I landed that CL but it w
jschuh 2013/01/07 22:24:14 I understand that generally, but in security sensi
jschuh 2013/01/07 22:24:14 Yep.
danakj 2013/01/07 22:56:37 Sure, I'm just not sure why you see something like
jschuh 2013/01/08 00:08:45 I appreciate that it seems arbitrary, but it's the
jschuh 2013/01/08 00:43:32 Antoine provided some context in was lacking (in t
182 return false; 185 return false;
183 r->set_width(w); 186 r->set_width(w);
184 r->set_height(h); 187 r->set_height(h);
185 return true; 188 return true;
186 } 189 }
187 190
188 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { 191 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) {
189 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); 192 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height()));
190 } 193 }
191 194
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 m->WriteInt(p.width()); 261 m->WriteInt(p.width());
259 m->WriteInt(p.height()); 262 m->WriteInt(p.height());
260 } 263 }
261 264
262 bool ParamTraits<gfx::Rect>::Read(const Message* m, 265 bool ParamTraits<gfx::Rect>::Read(const Message* m,
263 PickleIterator* iter, 266 PickleIterator* iter,
264 gfx::Rect* r) { 267 gfx::Rect* r) {
265 int x, y, w, h; 268 int x, y, w, h;
266 if (!m->ReadInt(iter, &x) || 269 if (!m->ReadInt(iter, &x) ||
267 !m->ReadInt(iter, &y) || 270 !m->ReadInt(iter, &y) ||
268 !m->ReadInt(iter, &w) || 271 !m->ReadInt(iter, &w) || w < 0 ||
269 !m->ReadInt(iter, &h)) 272 !m->ReadInt(iter, &h) || h < 0 ||
273 (h && w > ((std::numeric_limits<int>::max() / 4) / h)))
piman 2013/01/07 19:05:56 nit: it would be even better to serialize p.origin
jschuh 2013/01/07 22:24:14 Yep.
270 return false; 274 return false;
271 r->set_x(x); 275 r->set_x(x);
272 r->set_y(y); 276 r->set_y(y);
273 r->set_width(w); 277 r->set_width(w);
274 r->set_height(h); 278 r->set_height(h);
275 return true; 279 return true;
276 } 280 }
277 281
278 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { 282 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) {
279 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), 283 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ 368 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
365 #include "content/public/common/common_param_traits_macros.h" 369 #include "content/public/common/common_param_traits_macros.h"
366 } // namespace IPC 370 } // namespace IPC
367 371
368 // Generate param traits log methods. 372 // Generate param traits log methods.
369 #include "ipc/param_traits_log_macros.h" 373 #include "ipc/param_traits_log_macros.h"
370 namespace IPC { 374 namespace IPC {
371 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ 375 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
372 #include "content/public/common/common_param_traits_macros.h" 376 #include "content/public/common/common_param_traits_macros.h"
373 } // namespace IPC 377 } // namespace IPC
OLDNEW
« no previous file with comments | « content/common/cc_messages_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698