Skip to content

Fix use-after-free in json_validator sample #3668

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

Merged
merged 3 commits into from
Jul 17, 2025
Merged

Conversation

riverar
Copy link
Collaborator

@riverar riverar commented Jul 16, 2025

String::from_utf8_lossy returns a Cow<'_, str> that references the original memory when the input is considered valid UTF-8. Calling .into_owned() forces allocation of an owned String, allowing us to safely free the FFI memory with CoTaskMemFree.

Copy link
Collaborator

@kennykerr kennykerr left a comment

Choose a reason for hiding this comment

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

Well spotted!

@kennykerr kennykerr merged commit 99208c8 into master Jul 17, 2025
29 checks passed
@kennykerr kennykerr deleted the rafael/fix-json-sample branch July 17, 2025 17:59
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.

2 participants