Skip to content

agent-driven: Fix soundness in try_create_array, add safety comments#239

Merged
Manishearth merged 1 commit into
rust-fuzz:mainfrom
Manishearth:fix-soundness
Jun 22, 2026
Merged

agent-driven: Fix soundness in try_create_array, add safety comments#239
Manishearth merged 1 commit into
rust-fuzz:mainfrom
Manishearth:fix-soundness

Conversation

@Manishearth

Copy link
Copy Markdown
Member

Found while running a safety audit with Gemini Next

The main safety bug was that we were creating an uninitialized slice type so we could write to it.

The safety comments are also agent generated, but they seem fine. I can remove them if desired.

x.retain(|&c| c != 0);
// SAFETY: all zero bytes have been removed
// SAFETY:
// Contract from `CString::from_vec_unchecked`: the vector must not contain

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's a neat way to write down safety comments in a more structured way. I will, um, yoink this.

If only there was a way to reference the contracts without repeating them a bunch from what's already in the doc for the method... 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah that's been my rule about good safety comments for a while: list the things you need to prove, then prove them.

Review becomes double checking you got all the invariants (easy if occasionally tedious) and then checking the local proof (usually easy, sometimes not)

@Manishearth Manishearth merged commit cd35bd2 into rust-fuzz:main Jun 22, 2026
6 checks passed
@Manishearth Manishearth deleted the fix-soundness branch June 22, 2026 23:06
// SAFETY: all zero bytes have been removed
// SAFETY:
// Contract from `CString::from_vec_unchecked`: the vector must not contain
// any interior nul (zero) bytes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Isn't the canonical name for the zero byte a null byte (not nul or nil for that matter) as per K&R =)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nul is what it is called in the context of strings

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

thanks. I had done a similar PR and debated to use null or nul when talking about an array of ascii bytes. Sounds like I should have used nul in the comment.

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.

3 participants