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

Segmentation fault when using string created from empty array #1579

Closed
aturley opened this issue Feb 13, 2017 · 1 comment · Fixed by #1582
Closed

Segmentation fault when using string created from empty array #1579

aturley opened this issue Feb 13, 2017 · 1 comment · Fixed by #1582
Assignees
Labels
triggers release Major issue that when fixed, results in an "emergency" release

Comments

@aturley
Copy link
Member

aturley commented Feb 13, 2017

System

OS:

OSX 10.11.6

compiler:

0.10.0-7c7e036 [release]
compiled with: llvm 3.8.1 -- Apple LLVM version 7.3.0 (clang-703.0.29)

Issue

Observed Behavior

Using a string that is created using String.from_array where the array is empty results in a segmentation fault.

Expected Behavior

A string that is created using String.from_array should behave like a zero-length string.

Steps to Reproduce

This program reproduces the issue:

actor Main
  new create(env: Env) =>
    let s = String.from_array(recover Array[U8] end)
    env.out.print("before")
    env.out.print("'" + s + "'")
    env.out.print("after")

Additional information

I ran the reproduction program (above) in lldb. Here's the backtrace after it segfaults:

(lldb) bt
* thread #2: tid = 0x859eae, 0x00007fff8aafafd6 libsystem_platform.dylib`_platform_memmove$VARIANT$Haswell + 182, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00007fff8aafafd6 libsystem_platform.dylib`_platform_memmove$VARIANT$Haswell + 182
    frame #1: 0x0000000100003855 string-from-empty-array`Pointer_U8_val_box__copy_to_oZo + 21
    frame #2: 0x000000010000366c string-from-empty-array`String_iso__append_oo(this=0x00000001097d6480, s=0x00000001097d6460) + 124 at string.pony:1108
    frame #3: 0x000000010000335d string-from-empty-array`String_val_add_oo(this=0x0000000100014fc0, that=0x00000001097d6460) + 141 at string.pony:1118
    frame #4: 0x0000000100002f7b string-from-empty-array`Main_tag_create_oo(this=0x00000001097ff000, env=0x00000001097fe800) + 283 at main.pony:5
    frame #5: 0x00000001000015a5 string-from-empty-array`Main_Dispatch + 117
    frame #6: 0x0000000100004d92 string-from-empty-array`handle_message + 530
    frame #7: 0x000000010000e084 string-from-empty-array`run_thread + 1332
    frame #8: 0x00007fff8b28499d libsystem_pthread.dylib`_pthread_body + 131
    frame #9: 0x00007fff8b28491a libsystem_pthread.dylib`_pthread_start + 168
    frame #10: 0x00007fff8b282351 libsystem_pthread.dylib`thread_start + 13
(lldb) 
@jemc
Copy link
Member

jemc commented Feb 13, 2017

Looks like String._append is still assuming that String always has a null byte at the end.

We need someone to rewrite the logic in String._append to be aware of the possibility that not all strings are internally represented as being null-terminated. And we'll also want tests that prove correct behaviour in these circumstances, both for the case of zero-length string being appended, and for the case of an immutable string slice with no null-terminator, that was created via String.trim.

@jemc jemc added bug: 3 - ready for work triggers release Major issue that when fixed, results in an "emergency" release labels Feb 13, 2017
@Theodus Theodus self-assigned this Feb 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triggers release Major issue that when fixed, results in an "emergency" release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants