Skip to content

Remove an unsafe block#178

Merged
knutwalker merged 1 commit into
neo4j-labs:mainfrom
ChayimFriedman2:avoid-ub
Jul 21, 2024
Merged

Remove an unsafe block#178
knutwalker merged 1 commit into
neo4j-labs:mainfrom
ChayimFriedman2:avoid-ub

Conversation

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 commented Jul 21, 2024

The code was incorrect, and it caused UB in the wild, because BytesMut::reserve() reserves len+X, not capacity+X.

But even without that bug, this unsafe code was UB, since treating uninitialized integers as initialized is UB.

Fortunately, the unsafe code can be eliminated completely, and yet without zeroing the array.

You may consider yanking the affected versions.

The code was incorrect, and [it caused UB in the wild](https://stackoverflow.com/q/78776053/7884305), because `BytesMut::reserve()` reserves **len**+X, not **capacity**+X.

But even without that bug, this unsafe code was UB, since [treating uninitialized integers as initialized is UB](https://doc.rust-lang.org/stable/reference/behavior-considered-undefined.html).

Fortunately, the unsafe code can be eliminated completely, and yet without zeroing the array.
@knutwalker knutwalker merged commit e404ea2 into neo4j-labs:main Jul 21, 2024
knutwalker pushed a commit that referenced this pull request Jul 22, 2024
@knutwalker
Copy link
Copy Markdown
Contributor

Thanks for fixing this!

I just released 0.7.2 with this fix and yanked all previous 0.7.x releases.

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