OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" | 7 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 if (AddWouldOverflow(string_length, | 124 if (AddWouldOverflow(string_length, |
125 NACL_OFFSETOF(SerializedString, string_bytes))) { | 125 NACL_OFFSETOF(SerializedString, string_bytes))) { |
126 // Adding the length to the fixed portion would overflow. | 126 // Adding the length to the fixed portion would overflow. |
127 return 0; | 127 return 0; |
128 } | 128 } |
129 return static_cast<uint32_t>(NACL_OFFSETOF(SerializedString, string_bytes) | 129 return static_cast<uint32_t>(NACL_OFFSETOF(SerializedString, string_bytes) |
130 + string_length); | 130 + string_length); |
131 break; | 131 break; |
132 } | 132 } |
133 case PP_VARTYPE_ARRAY_BUFFER: { | 133 case PP_VARTYPE_ARRAY_BUFFER: { |
134 uint32_t buffer_length = PPBVarArrayBufferInterface()->ByteLength(var); | 134 uint32_t buffer_length = 0; |
| 135 if (!PPBVarArrayBufferInterface()->ByteLength(var, &buffer_length)) |
| 136 return 0; |
135 buffer_length = RoundedStringBytes(buffer_length); | 137 buffer_length = RoundedStringBytes(buffer_length); |
136 if (AddWouldOverflow(buffer_length, | 138 if (AddWouldOverflow(buffer_length, |
137 NACL_OFFSETOF(SerializedString, string_bytes))) { | 139 NACL_OFFSETOF(SerializedString, string_bytes))) { |
138 // Adding the length to the fixed portion would overflow. | 140 // Adding the length to the fixed portion would overflow. |
139 return 0; | 141 return 0; |
140 } | 142 } |
141 return static_cast<uint32_t>(NACL_OFFSETOF(SerializedString, string_bytes) | 143 return static_cast<uint32_t>(NACL_OFFSETOF(SerializedString, string_bytes) |
142 + buffer_length); | 144 + buffer_length); |
143 break; | 145 break; |
144 } | 146 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 reinterpret_cast<const void*>(str), | 221 reinterpret_cast<const void*>(str), |
220 string_length); | 222 string_length); |
221 // Fill padding bytes with zeros. | 223 // Fill padding bytes with zeros. |
222 memset(reinterpret_cast<void*>(ss->string_bytes + string_length), 0, | 224 memset(reinterpret_cast<void*>(ss->string_bytes + string_length), 0, |
223 RoundedStringBytes(string_length) - string_length); | 225 RoundedStringBytes(string_length) - string_length); |
224 element_size = NACL_OFFSETOF(SerializedString, string_bytes) | 226 element_size = NACL_OFFSETOF(SerializedString, string_bytes) |
225 + RoundedStringBytes(string_length); | 227 + RoundedStringBytes(string_length); |
226 break; | 228 break; |
227 } | 229 } |
228 case PP_VARTYPE_ARRAY_BUFFER: { | 230 case PP_VARTYPE_ARRAY_BUFFER: { |
229 uint32_t buffer_length = | 231 uint32_t buffer_length = 0; |
230 PPBVarArrayBufferInterface()->ByteLength(vars[i]); | 232 PPBVarArrayBufferInterface()->ByteLength(vars[i], &buffer_length); |
231 SerializedString* ss = reinterpret_cast<SerializedString*>(p); | 233 SerializedString* ss = reinterpret_cast<SerializedString*>(p); |
232 ss->fixed.u.string_length = buffer_length; | 234 ss->fixed.u.string_length = buffer_length; |
233 memcpy(reinterpret_cast<void*>(ss->string_bytes), | 235 memcpy(reinterpret_cast<void*>(ss->string_bytes), |
234 PPBVarArrayBufferInterface()->Map(vars[i]), | 236 PPBVarArrayBufferInterface()->Map(vars[i]), |
235 buffer_length); | 237 buffer_length); |
236 // Fill padding bytes with zeros. | 238 // Fill padding bytes with zeros. |
237 memset(reinterpret_cast<void*>(ss->string_bytes + buffer_length), 0, | 239 memset(reinterpret_cast<void*>(ss->string_bytes + buffer_length), 0, |
238 RoundedStringBytes(buffer_length) - buffer_length); | 240 RoundedStringBytes(buffer_length) - buffer_length); |
239 element_size = NACL_OFFSETOF(SerializedString, string_bytes) | 241 element_size = NACL_OFFSETOF(SerializedString, string_bytes) |
240 + RoundedStringBytes(buffer_length); | 242 + RoundedStringBytes(buffer_length); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 return false; | 515 return false; |
514 } | 516 } |
515 // Read the serialized PP_Vars into the allocated memory. | 517 // Read the serialized PP_Vars into the allocated memory. |
516 if (!DeserializePpVar(bytes, length, vars, argc)) { | 518 if (!DeserializePpVar(bytes, length, vars, argc)) { |
517 return false; | 519 return false; |
518 } | 520 } |
519 return true; | 521 return true; |
520 } | 522 } |
521 | 523 |
522 } // namespace ppapi_proxy | 524 } // namespace ppapi_proxy |
OLD | NEW |