-
-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory corruption that can arise from Array.copy_to
- Loading branch information
1 parent
17ee1a5
commit 2c55c1f
Showing
3 changed files
with
115 additions
and
5 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,23 @@ | ||
## Fix for potential memory corruption in Array.copy_to() | ||
|
||
`Array.copy_to()` did not check whether the source or destination Arrays had been initialized or whether the requested number of elements to be copied exceeded the number of available elements (allocated memory). These issues would result in potential dereferencing of a null pointer or attempts to access unallocated memory. | ||
|
||
Before this fix, the following code would print `11` then `0`: | ||
|
||
```pony | ||
actor Main | ||
new create(e: Env) => | ||
var src: Array[U8] = [1] | ||
var dest: Array[U8] = [11; 1; 2; 3; 4; 5; 6] | ||
try | ||
e.out.print(dest(0)?.string()) | ||
end | ||
src.copy_to(dest, 11, 0, 10) | ||
try | ||
e.out.print(dest(0)?.string()) | ||
end | ||
``` | ||
|
||
After the fix, this code correctly prints `11` and `11`. |
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
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