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

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: rebase and applied senorblanco+haraken feedbac Created 5 years, 1 month 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 // TODO(junov): crbug.com/536816
185 // Instead of crashing when array buffer allocation fails, we could
186 // and probably should use DOMArrayBuffer::createOrNull and reject
187 // the promise with a RangeError exception when crewation returns null.
haraken 2015/10/29 18:58:37 creation
Justin Novosad 2015/11/05 00:17:52 Done.
188 // The specs for all crypto methods that use this code state: "If the
189 // following steps or referenced procedures say to throw an error,
190 // reject promise with the returned error and then terminate the algorithm."
191 // In this case, the procedure of allocating an ArrayBuffer is not explicitl y
192 // referenced in the algorithms laid out in the spec, but one could argue
193 // that it is implied, and the ECMAScript spec says that failure to
194 // allocate the buffer should result in a RangeError being thrown.
195 // http://ecma-international.org/ecma-262/6.0/#sec-createbytedatablock
196 // The crypto spec probably needs to be edited to be more explicit about
197 // this issue.
198 m_resolver->resolve(DOMArrayBuffer::deprecatedCreateOrCrash(bytes, bytesSize ));
185 clearResolver(); 199 clearResolver();
186 } 200 }
187 201
188 void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length) 202 void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length)
189 { 203 {
190 if (!m_resolver) 204 if (!m_resolver)
191 return; 205 return;
192 206
193 ScriptState* scriptState = m_resolver->scriptState(); 207 ScriptState* scriptState = m_resolver->scriptState();
194 ScriptState::Scope scope(scriptState); 208 ScriptState::Scope scope(scriptState);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 m_cancel.clear(); 260 m_cancel.clear();
247 clearResolver(); 261 clearResolver();
248 } 262 }
249 263
250 ScriptPromise CryptoResultImpl::promise() 264 ScriptPromise CryptoResultImpl::promise()
251 { 265 {
252 return m_resolver ? m_resolver->promise() : ScriptPromise(); 266 return m_resolver ? m_resolver->promise() : ScriptPromise();
253 } 267 }
254 268
255 } // namespace blink 269 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698