Skip to content

Commit

Permalink
Handle OOM in btoa (oven-sh#12353)
Browse files Browse the repository at this point in the history
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
  • Loading branch information
Jarred-Sumner and Jarred-Sumner authored Jul 6, 2024
1 parent 57d2290 commit cd97c21
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,10 @@ JSC_DEFINE_HOST_FUNCTION(functionBTOA,
LChar* ptr;
unsigned length = encodedString.length();
auto dest = WTF::String::createUninitialized(length, ptr);
if (UNLIKELY(dest.isNull())) {
throwOutOfMemoryError(globalObject, throwScope);
return JSC::JSValue::encode(JSC::JSValue {});
}
WTF::StringImpl::copyCharacters(ptr, encodedString.span16());
encodedString = WTFMove(dest);
}
Expand Down

0 comments on commit cd97c21

Please sign in to comment.