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

fix(ext/ffi): Check CStr for UTF-8 validity on read #15318

Merged
merged 14 commits into from
Aug 5, 2022

Conversation

aapoalas
Copy link
Collaborator

Previous performance work on op_ffi_cstr_read was a bit too optimistic about what it can do.

This PR fixes the optimism by properly checking for UTF-8 validity before giving the bytes to V8 for v8::String creation.

@aapoalas
Copy link
Collaborator Author

@phosra Ping for review.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

Thanks for the patch @aapoalas - could you add a test?

@aapoalas
Copy link
Collaborator Author

aapoalas commented Jul 27, 2022

Thanks for the patch @aapoalas - could you add a test?

Added a test that verifies both that the getArrayBuffer function correctly accesses the expected bytes and that trying to create a string from invalid UTF-8 will now throw.

EDIT: Here's what the getCString returns without this fix:

Invalid UTF-8 characters to v8::String: �������������

ext/ffi/lib.rs Outdated Show resolved Hide resolved
@littledivy littledivy merged commit 5699108 into denoland:main Aug 5, 2022
dsherret pushed a commit that referenced this pull request Aug 11, 2022
@aapoalas aapoalas deleted the fix-ext-ffi-cstr-check-utf8 branch October 9, 2022 08:01
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.

None yet

4 participants