Skip to content

[6.2] LoopRotate: Fix a by reference map bug under reallocation #82027

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

Conversation

aschwaighofer
Copy link
Contributor

Issue:
When using a densemap subscript expression on both sides of an assignment in the same statement of the same map we run into the issue that the map can reallocate because of the assignment but we are referencing the value of the RHS map subscript by reference -- i.e we can reference deallocated memory.

Not good.

Scope: A "silent" memory error that one might run into including the reporter of the bug.

Risk: Extremely, low. The fix is spliting an assignment from a map value to a map entry into: A value assignment of the map value to a local. And then storing the local in the map entry forgoing the reference of reallocated memory bug.

  valueMap[bfi] = valueMap[bfi->getBorrowedValue()];

=>

  auto mappedMValue = valueMap[bfi->getBorrowedValue()];
  valueMap[bfi] = mappedValue;

Reviewed by: Meghana G, Erik E., Joe G.

Testing: The fix was tested on the reporting project.

Original PR: #81995

rdar://151031297

Issue:
When using a densemap subscript expression on both sides of an
assignment in the same statement of the same map we run into the issue
that the map can reallocate because of the assignment but we are
referencing the value of the RHS map subscript by reference --
i.e we can reference deallocated memory.

Not good.

Scope: A "silent" memory error that one might run into including the
reporter of the bug.

Risk: Extremely, low. The fix is spliting an assignment from a map value
to a map entry into: A value assignment of the map value to a local. And
then storing the local in the map entry forgoing the reference of
reallocated memory bug.

```
  valueMap[bfi] = valueMap[bfi->getBorrowedValue()];

=>

  auto mappedMValue = valueMap[bfi->getBorrowedValue()];
  valueMap[bfi] = mappedValue;
```

Reviewed by: Meghana G, Erik E., Joe G.

Testing: The fix was tested on the reporting project.

rdar://151031297
@aschwaighofer aschwaighofer requested a review from a team as a code owner June 5, 2025 18:58
@aschwaighofer
Copy link
Contributor Author

@swift-ci test

@aschwaighofer
Copy link
Contributor Author

@swift-ci test macOS

@aschwaighofer aschwaighofer merged commit 423fef0 into swiftlang:release/6.2 Jun 6, 2025
5 checks passed
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