Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit c360086

Browse files
authored
table.fill: Bounds check before mutating the table (#106)
Fixes #105
1 parent 1e652dd commit c360086

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

document/core/exec/instructions.rst

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -651,42 +651,49 @@ Table Instructions
651651

652652
11. Pop the value :math:`\I32.\CONST~i` from the stack.
653653

654-
12. If :math:`n` is :math:`0`, then:
654+
12. If :math:`i + n` is larger than the length of :math:`\X{tab}.\TIELEM`, then:
655655

656-
a. If :math:`i` is larger than the length of :math:`\X{tab}.\TIELEM`, then:
656+
a. Trap.
657657

658-
i. Trap.
658+
12. If :math:`n` is :math:`0`, then:
659659

660-
12. Else:
660+
a. Return.
661661

662-
a. Push the value :math:`\I32.CONST~i` to the stack.
662+
13. Push the value :math:`\I32.CONST~i` to the stack.
663663

664-
b. Push the value :math:`\val` to the stack.
664+
14. Push the value :math:`\val` to the stack.
665665

666-
c. Execute the instruction :math:`\TABLESET~x`.
666+
15. Execute the instruction :math:`\TABLESET~x`.
667667

668-
d. Push the value :math:`\I32.CONST~(i+1)` to the stack.
668+
16. Push the value :math:`\I32.CONST~(i+1)` to the stack.
669669

670-
e. Push the value :math:`\val` to the stack.
670+
17. Push the value :math:`\val` to the stack.
671671

672-
f. Push the value :math:`\I32.CONST~(n-1)` to the stack.
672+
18. Push the value :math:`\I32.CONST~(n-1)` to the stack.
673673

674-
c. Execute the instruction :math:`\TABLEFILL~x`.
674+
19. Execute the instruction :math:`\TABLEFILL~x`.
675675

676676
.. math::
677677
\begin{array}{l}
678-
\begin{array}{lcl@{\qquad}l}
679-
S; F; (\I32.\CONST~i)~\val~(\I32.\CONST~(n+1))~(\TABLEFILL~x) &\stepto& S'; F; (\I32.\CONST~i)~\val~(\TABLESET~x)~(\I32.\CONST~(i+1))~\val~(\I32.\CONST~n)~(\TABLEFILL~x)
680-
\end{array} \\
681-
\begin{array}{lcl@{\qquad}l}
682-
S; F; (\I32.\CONST~i)~\val~(\I32.\CONST~0)~(\TABLEFILL~x) &\stepto& S'; F; \epsilon
683-
\end{array}
684-
\\ \qquad
685-
(\iff i \leq |\STABLES[F.\AMODULE.\MITABLES[x]]|) \\
686-
\begin{array}{lcl@{\qquad}l}
687-
S; F; (\I32.\CONST~i)~\val~(\I32.\CONST~0)~(\TABLEFILL~x) &\stepto& S; F; \TRAP
688-
\end{array}
689-
\\ \qquad
678+
S; F; (\I32.\CONST~i)~\val~(\I32.\CONST~n)~(\TABLEFILL~x)
679+
\quad\stepto\quad S; F; \TRAP
680+
\\ \qquad
681+
\begin{array}[t]{@{}r@{~}l@{}}
682+
(\iff & i + n > |S.\STABLES[F.\AMODULE.\MITABLES[x]].\TIELEM|) \\
683+
\end{array}
684+
\\[1ex]
685+
S; F; (\I32.\CONST~i)~\val~(\I32.\CONST~0)~(\TABLEFILL~x)
686+
\quad\stepto\quad S; F; \epsilon
687+
\\ \qquad
688+
(\otherwise)
689+
\\[1ex]
690+
S; F; (\I32.\CONST~i)~\val~(\I32.\CONST~n+1)~(\TABLEFILL~x)
691+
\quad\stepto\quad S; F;
692+
\begin{array}[t]{@{}l@{}}
693+
(\I32.\CONST~i)~\val~(\TABLESET~x) \\
694+
(\I32.\CONST~i+1)~\val~(\I32.\CONST~n)~(\TABLEFILL~x) \\
695+
\end{array}
696+
\\ \qquad
690697
(\otherwise) \\
691698
\end{array}
692699

0 commit comments

Comments
 (0)