Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying a small string into a larger string container copies data beyond the end of the small string #814

Open
sbillig opened this issue Nov 16, 2022 · 1 comment

Comments

@sbillig
Copy link
Collaborator

sbillig commented Nov 16, 2022

What is wrong?

Copying a smaller string into a bigger one (that is, one with a larger maximum size) results in an out-of-bounds memory copy.
Example:

let s1: String<3> = "abc"
let foo: Foo = Foo(x: 123)
let s2: String<4> = s1 // 4 bytes of memory, containing "abc" and the value 123

struct Foo {
  x: u8
}

How can it be fixed

#777 introduces a StringSizeIncrease type adjustment. This could be used in MIR to insert a memcopy that copies the smaller string's number of bytes.

@sbillig sbillig mentioned this issue Nov 16, 2022
3 tasks
@Y-Nak
Copy link
Member

Y-Nak commented Nov 21, 2022

Is this Issue about performance? I don't think this leads to a bug because a string object stores its actual length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants