Skip to content

Fix use-after-free in json_validator sample#3668

Merged
kennykerr merged 3 commits into
masterfrom
rafael/fix-json-sample
Jul 17, 2025
Merged

Fix use-after-free in json_validator sample#3668
kennykerr merged 3 commits into
masterfrom
rafael/fix-json-sample

Conversation

@riverar

@riverar riverar commented Jul 16, 2025

Copy link
Copy Markdown
Collaborator

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.

Comment thread crates/samples/components/json_validator/src/lib.rs Outdated

@kennykerr kennykerr left a comment

Copy link
Copy Markdown
Collaborator

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