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 buffer zeroing with offset in map_buffer #2916

Merged
merged 4 commits into from Jul 31, 2022

Conversation

nical
Copy link
Contributor

@nical nical commented Jul 26, 2022

Checklist

  • Run cargo clippy.
  • Add change to CHANGELOG.md. See simple instructions inside file.

Connections

None.

Description

The buffer zeroing code in map_buffer currently writes out of bounds if a non zero offset is passed.

This is because the map_buffer code passes the mapped_pointer + uninitialized.start to write_bytes, however the uninitialized range is relative to the start of the buffer while our mapped pointer is offset.

The offset parameter has to be subtracted from the uninitialized range so that the new range is relative to the mapped range and avoid (very scary) out of bounds writes.

Testing

None.

The tracked uninitialized ranges are relative to the start of the buffer, however when mapping the buffer at an offset the resulting pointer is not the start of the buffer, and therefore the offset has to be taken into account.
Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

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

Wow.

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Very nice stuff

@cwfitzgerald cwfitzgerald enabled auto-merge (squash) July 31, 2022 21:54
@cwfitzgerald cwfitzgerald merged commit a05c8dc into gfx-rs:master Jul 31, 2022
@nical nical deleted the map_clear_offset branch July 31, 2022 23: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

3 participants