Skip to content

[release/dev17.14] Fix aligned buffer write #11862

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 7 commits into from
May 15, 2025

Conversation

github-actions[bot]
Copy link

@github-actions github-actions bot commented May 15, 2025

Backport of #11861 to release/dev17.14

/cc @333fred

Customer Impact

Regression

Testing

Dedicated testing for the scenario was added.

Risk

Low. This fixes a small looping bug that only reproduces in particularly edge cases.

333fred added 7 commits May 15, 2025 01:15
This is a particularly subtle bug that requires a chunk (or remaining bit of a chunk) and the destination buffer being _exactly_ the same size. When this happens, the following sequence occurs:

1. `source.Length` and `destination.Length` are exactly aligned. This means that we do not enter the `if` on line 450, and `endOfChunkWritten` will be true.
2. We slice `destination` by `source.Length`. This leaves us with a `destination` that has 0 elements, and `IsEmpty` is true.
3. Because `endOfChunkWritten` is true, we enter the `if` on line 466. This increments us to the next chunk.
4. On line 472 (in the before diff), `destination.IsEmpty` is true, so we enter the `if`, and break out of the loop, never reseting `charIndex` to 0.
5. 4 happens again, this time on line 480 (in the before diff). Again, we do not reset `charIndex` to 0.

To fix this, we want to unconditionally reset `charIndex` when we increment a chunk, not wait until after the destination has been checked for empty.
@github-actions github-actions bot requested a review from a team as a code owner May 15, 2025 01:15
@333fred 333fred enabled auto-merge (squash) May 15, 2025 01:17
@333fred 333fred merged commit 3c473a9 into release/dev17.14 May 15, 2025
11 checks passed
@333fred 333fred deleted the backport/pr-11861-to-release/dev17.14 branch May 15, 2025 01:50
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