Skip to content

Commit

Permalink
fix: protect string encoding failure. (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall authored Jun 13, 2024
2 parents d9aaff7 + 78a6305 commit 345ffdf
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bridge/core/frame/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ AtomicString Window::btoa(const AtomicString& source, ExceptionState& exception_
const size_t output_size = modp_b64_encode_data(reinterpret_cast<char*>(buffer.data()),
reinterpret_cast<const char*>(source.Character8()), source.length());
assert(output_size == encode_len);
if (output_size != encode_len || buffer.empty()) {
exception_state.ThrowException(ctx(), ErrorType::TypeError, "The string encode failed.");
return AtomicString::Empty();
}

return {ctx(), buffer.data(), buffer.size()};
}
Expand Down

0 comments on commit 345ffdf

Please sign in to comment.