Skip to content

Commit

Permalink
Stop using Vector::unsafeAppendWithoutCapacityCheck() in WasmFunction…
Browse files Browse the repository at this point in the history
…Parser.h

https://bugs.webkit.org/show_bug.cgi?id=265161

Reviewed by Darin Adler.

* Source/JavaScriptCore/wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::parseExpression):

Canonical link: https://commits.webkit.org/271142@main
  • Loading branch information
cdumez committed Nov 27, 2023
1 parent cb498fb commit f9d95b0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Source/JavaScriptCore/wasm/WasmFunctionParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3008,12 +3008,22 @@ FOR_EACH_WASM_MEMORY_STORE_OP(CREATE_CASE)
WASM_PARSER_FAIL_IF(numberOfTargets == std::numeric_limits<uint32_t>::max(), "br_table's number of targets is too big ", numberOfTargets);

WASM_PARSER_FAIL_IF(!targets.tryReserveCapacity(numberOfTargets), "can't allocate memory for ", numberOfTargets, " br_table targets");
for (uint32_t i = 0; i < numberOfTargets; ++i) {
String errorMessage;
targets.appendUsingFunctor(numberOfTargets, [&](size_t i) -> ControlType* {
uint32_t target;
WASM_PARSER_FAIL_IF(!parseVarUInt32(target), "can't get ", i, "th target for br_table");
WASM_PARSER_FAIL_IF(target >= m_controlStack.size(), "br_table's ", i, "th target ", target, " exceeds control stack size ", m_controlStack.size());
targets.unsafeAppendWithoutCapacityCheck(&m_controlStack[m_controlStack.size() - 1 - target].controlData);
}
if (UNLIKELY(!parseVarUInt32(target))) {
if (errorMessage.isNull())
errorMessage = WTF::makeString("can't get ", i, "th target for br_table");
return nullptr;
}
if (UNLIKELY(target >= m_controlStack.size())) {
if (errorMessage.isNull())
errorMessage = WTF::makeString("br_table's ", i, "th target ", target, " exceeds control stack size ", m_controlStack.size());
return nullptr;
}
return &m_controlStack[m_controlStack.size() - 1 - target].controlData;
});
WASM_PARSER_FAIL_IF(!errorMessage.isNull(), errorMessage);

WASM_PARSER_FAIL_IF(!parseVarUInt32(defaultTargetIndex), "can't get default target for br_table");
WASM_PARSER_FAIL_IF(defaultTargetIndex >= m_controlStack.size(), "br_table's default target ", defaultTargetIndex, " exceeds control stack size ", m_controlStack.size());
Expand Down

0 comments on commit f9d95b0

Please sign in to comment.