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

do not panic on bad utf-8 received from ffi #728

Merged
merged 4 commits into from
Oct 19, 2019
Merged

do not panic on bad utf-8 received from ffi #728

merged 4 commits into from
Oct 19, 2019

Conversation

r10s
Copy link
Member

@r10s r10s commented Oct 19, 2019

prefer to_string_lossy() for converting c-strings to String
c-strings may always be badly formatted and this should never lead to a panic.

fixes deltachat/deltachat-android#1065

see also #674 #679 that already does the conversion on other places.

@r10s r10s changed the title do not panic on bad utf-8 received from ffi [wip] do not panic on bad utf-8 received from ffi Oct 19, 2019
@r10s r10s changed the title [wip] do not panic on bad utf-8 received from ffi do not panic on bad utf-8 received from ffi Oct 19, 2019
ffi_msg.message.set_file(as_str(file), as_opt_str(filemime))
ffi_msg.message.set_file(
to_string_lossy(file),
to_opt_string_lossy(filemime).as_ref().map(|x| x.as_str()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably is safe, but I had to think about that. I've still not studied or fully internalised the rules on when rust keeps objects alive though, only have a vague notion and know that it allows terrible mistakes with raw pointers in some cases.
I'd have stored the string in a local variable instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should also provide a to_opt_path_lossy() function that does not crashes but returns None when utf-8 is bad in some way. but i wanted to fix this pr mainly the android crash and similar ffi functions.

there are also some as_str() calls eg. in the mime-parser that should probably be replaced the same way.

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

Successfully merging this pull request may close these issues.

DELTA Stops when sending Emoji. On Android 4.
2 participants