Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types: fix invalid memory access on setting non-contiguous array indexes
When setting an array index which is beyond the end of the last currently preallocated chunk and not evenly divisible by the chunk size, the array entries list was not properly reallocated, resulting in invalid memory writes. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
- Loading branch information
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
When setting an array index which is beyond the end of the last currently | ||
preallocated chunk and not evenly divisible by the chunk size, the array | ||
entries list was not properly reallocated resulting in invalid memory | ||
writes. | ||
|
||
-- Testcase -- | ||
{% | ||
for (i = 0; i < 32; i++) { | ||
a = []; | ||
a[i] = true; | ||
print(length(a), "\n"); | ||
} | ||
%} | ||
-- End -- | ||
|
||
-- Expect stdout -- | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
7 | ||
8 | ||
9 | ||
10 | ||
11 | ||
12 | ||
13 | ||
14 | ||
15 | ||
16 | ||
17 | ||
18 | ||
19 | ||
20 | ||
21 | ||
22 | ||
23 | ||
24 | ||
25 | ||
26 | ||
27 | ||
28 | ||
29 | ||
30 | ||
31 | ||
32 | ||
-- End -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters