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

Side by Side Diff: third_party/WebKit/Source/modules/crypto/CryptoResultImpl.cpp

Issue 1414553002: Fix out-of-memory crashes related to ArrayBuffer allocation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 else 174 else
175 m_resolver->reject(DOMException::create(ec, errorDetails)); 175 m_resolver->reject(DOMException::create(ec, errorDetails));
176 clearResolver(); 176 clearResolver();
177 } 177 }
178 178
179 void CryptoResultImpl::completeWithBuffer(const void* bytes, unsigned bytesSize) 179 void CryptoResultImpl::completeWithBuffer(const void* bytes, unsigned bytesSize)
180 { 180 {
181 if (!m_resolver) 181 if (!m_resolver)
182 return; 182 return;
183 183
184 m_resolver->resolve(DOMArrayBuffer::create(bytes, bytesSize)); 184 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::createOrNull(bytes, bytesSiz e);
185 if (!buffer) {
186 // The specs for all crypto methods that use this code state: "If the
187 // following steps or referenced procedures say to throw an error,
188 // reject promise with the returned error and then terminate the algorit hm."
189 // In this case, the procedure of allocating an ArrayBuffer is not expli citly
190 // referenced in the algorithms laid out in the spec, but it is implied,
191 // and the ECMAScript spec says that failure to allocate the buffer shou ld
192 // result in a RangeError being thrown.
193 // http://ecma-international.org/ecma-262/6.0/#sec-createbytedatablock
194 m_resolver->reject(DOMException::create(V8RangeError, "Out of memory. Co uld not allocate buffer."));
195 } else {
196 m_resolver->resolve(buffer);
197 }
185 clearResolver(); 198 clearResolver();
186 } 199 }
187 200
188 void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length) 201 void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length)
189 { 202 {
190 if (!m_resolver) 203 if (!m_resolver)
191 return; 204 return;
192 205
193 ScriptState* scriptState = m_resolver->scriptState(); 206 ScriptState* scriptState = m_resolver->scriptState();
194 ScriptState::Scope scope(scriptState); 207 ScriptState::Scope scope(scriptState);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 m_cancel.clear(); 259 m_cancel.clear();
247 clearResolver(); 260 clearResolver();
248 } 261 }
249 262
250 ScriptPromise CryptoResultImpl::promise() 263 ScriptPromise CryptoResultImpl::promise()
251 { 264 {
252 return m_resolver ? m_resolver->promise() : ScriptPromise(); 265 return m_resolver ? m_resolver->promise() : ScriptPromise();
253 } 266 }
254 267
255 } // namespace blink 268 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698