Skip to content

Commit

Permalink
Merge pull request WebAssembly#465 from ShinWonho/array
Browse files Browse the repository at this point in the history
Fix OOB cases for `array.get/set`
  • Loading branch information
rossberg authored Nov 3, 2023
2 parents 267426c + 26ba9e2 commit 79d0a2a
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions document/core/exec/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -894,16 +894,20 @@ Reference Instructions
16. Push the value :math:`\val` to the stack.

.. math::
~\\[-1ex]
\begin{array}{lcl@{\qquad}l}
S; F; (\REFARRAYADDR~a)~(\I32.\CONST~i)~(\ARRAYGET\K{\_}\sx^?~x) &\stepto& \val
&
S; F; (\REFARRAYADDR~a)~(\I32.\CONST~i)~(\ARRAYGET\K{\_}\sx^?~x) \stepto \TRAP
\\ \qquad
(\iff i \geq |\SARRAYS[a].\AIFIELDS|)
\\[1ex]
S; F; (\REFARRAYADDR~a)~(\I32.\CONST~i)~(\ARRAYGET\K{\_}\sx^?~x) \stepto \val
\\ \qquad
\begin{array}[t]{@{}r@{~}l@{}}
(\iff & \expanddt(F.\AMODULE.\MITYPES[x]) = \TARRAY~\X{ft} \\
\land & \val = \unpackval^{\sx^?}_{\X{ft}}(S.\SARRAYS[a].\AIFIELDS[i]))
\end{array} \\
S; F; (\REFARRAYADDR~a)~(\I32.\CONST~i)~(\ARRAYGET\K{\_}\sx^?~x) &\stepto& \TRAP
& (\otherwise) \\
S; F; (\REFNULL~t)~(\I32.\CONST~i)~(\ARRAYGET\K{\_}\sx^?~x) &\stepto& \TRAP
\land & \val = \unpackval^{\sx^?}_{\X{ft}}(S.\SARRAYS[a].\AIFIELDS[i])) \\
\end{array}
\\[1ex]
S; F; (\REFNULL~t)~(\I32.\CONST~i)~(\ARRAYGET\K{\_}\sx^?~x) \stepto \TRAP
\end{array}
Expand Down Expand Up @@ -951,16 +955,20 @@ Reference Instructions
17. Replace the :ref:`field value <syntax-fieldval>` :math:`S.\SARRAYS[a].\AIFIELDS[i]` with :math:`\fieldval`.

.. math::
~\\[-1ex]
\begin{array}{lcl@{\qquad}l}
S; F; (\REFARRAYADDR~a)~(\I32.\CONST~i)~\val~(\ARRAYSET~x) &\stepto& S'; \epsilon
&
S; F; (\REFARRAYADDR~a)~(\I32.\CONST~i)~\val~(\ARRAYSET~x) \stepto \TRAP
\\ \qquad
(\iff i \geq |\SARRAYS[a].\AIFIELDS|)
\\[1ex]
S; F; (\REFARRAYADDR~a)~(\I32.\CONST~i)~\val~(\ARRAYSET~x) \stepto S'; \epsilon
\\ \qquad
\begin{array}[t]{@{}r@{~}l@{}}
(\iff & \expanddt(F.\AMODULE.\MITYPES[x]) = \TSTRUCT~\X{ft}^n \\
\land & S' = S \with \SARRAYS[a].\AIFIELDS[i] = \packval_{\X{ft}}(\val))
\end{array} \\
S; F; (\REFARRAYADDR~a)~(\I32.\CONST~i)~\val~(\ARRAYSET~x) &\stepto& \TRAP
& (\otherwise) \\
S; F; (\REFNULL~t)~(\I32.\CONST~i)~\val~(\ARRAYSET~x) &\stepto& \TRAP
\land & S' = S \with \SARRAYS[a].\AIFIELDS[i] = \packval_{\X{ft}}(\val)) \\
\end{array}
\\[1ex]
S; F; (\REFNULL~t)~(\I32.\CONST~i)~\val~(\ARRAYSET~x) \stepto \TRAP
\end{array}
Expand Down

0 comments on commit 79d0a2a

Please sign in to comment.