From 9c69d19f429fb3766fe60cd63accf7578fe16235 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Mon, 7 Oct 2024 05:15:41 -0500 Subject: [PATCH] [js-api] Fix up missing preconditions on allocations (#1793) --- document/js-api/index.bs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 034a17417f..8013e7456d 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -61,6 +61,9 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df url: valid/modules.html#valid-module text: valid text: WebAssembly module validation + text: valid limits; url: valid/types.html#valid-limits + text: valid memtype; url: valid/types.html#valid-memtype + text: valid tabletype; url: valid/types.html#valid-tabletype text: module grammar; url: binary/modules.html#binary-module text: custom section; url: binary/modules.html#custom-section text: customsec; url: binary/modules.html#binary-customsec @@ -108,9 +111,11 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: global_write; url: appendix/embedding.html#embed-global-write text: error; url: appendix/embedding.html#embed-error text: store; url: exec/runtime.html#syntax-store + text: limits; url: syntax/types.html#syntax-limits text: table type; url: syntax/types.html#syntax-tabletype text: table address; url: exec/runtime.html#syntax-tableaddr text: function address; url: exec/runtime.html#syntax-funcaddr + text: memory type; url: syntax/types.html#syntax-memtype text: memory address; url: exec/runtime.html#syntax-memaddr text: global address; url: exec/runtime.html#syntax-globaladdr text: extern address; url: exec/runtime.html#syntax-externaddr @@ -675,8 +680,8 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each The Memory(|descriptor|) constructor, when invoked, performs the following steps: 1. Let |initial| be |descriptor|["initial"]. 1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty. - 1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception. - 1. Let |memtype| be { min |initial|, max |maximum| }. + 1. Let |memtype| be the [=memory type=] { [=limits|min=] |initial|, [=limits|max=] |maximum| }. + 1. If |memtype| is not [=valid memtype|valid=], throw a {{RangeError}} exception. 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let (|store|, |memaddr|) be [=mem_alloc=](|store|, |memtype|). If allocation fails, throw a {{RangeError}} exception. 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. @@ -836,14 +841,16 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address 1. [=Throw=] a {{TypeError}} exception. 1. Let |initial| be |descriptor|["initial"]. 1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty. - 1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception. + 1. Let |type| be the [=table type=] { [=limits|min=] |initial|, [=limits|max=] |maximum| } |elementType|. + 1. If |type| is not [=valid tabletype|valid=], throw a {{RangeError}} exception. + + Note: Because tables may have up to 232 - 1 elements in validation, the checks for [=limits|min=] ≤ 232 - 1 and [=limits|max=] ≤ 232 - 1 in [=valid limits|limits validation=] cannot fail. 1. If |value| is missing, 1. Let |ref| be [=DefaultValue=](|elementType|). 1. Otherwise, 1. Let |ref| be [=?=] [=ToWebAssemblyValue=](|value|, |elementType|). - 1. Let |type| be the [=table type=] {[=table type|min=] |initial|, [=table type|max=] |maximum|} |elementType|. 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. - 1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, |ref|). + 1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|, |ref|). If allocation fails, throw a {{RangeError}} exception. 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. 1. [=initialize a table object|Initialize=] **this** from |tableaddr|.