Skip to content

🐛 Fix SequenceSet#xor crash when set is frozen #457

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 1 commit into from
Apr 29, 2025

Conversation

nevans
Copy link
Collaborator

@nevans nevans commented Apr 28, 2025

set ^ other and set.xor other are supposed to be safe transforms. But, unfortunately, they modified the receiver if it wasn't frozen, and crashed when it was!

The fix is trivial: convert self to dup.


Edited later to add: The bug wasn't as severe as I thought when I wrote the ticket and commit notes. (self | other) always returns a new SequenceSet so the original is unmodified. The test failed because SequenceSet#| returns a new set with the same frozen status as the receiver. But as a performance optimization, the #xor implementation uses (self | other).subtract(...) rather than (self | other) - .... So, when self is frozen, the result of (self | other) will be frozen too, and `subtract will crash (as the test showed).

@nevans nevans changed the base branch from sequence_set/fix-slice-inconsistent-frozen to master April 28, 2025 22:55
@nevans nevans added the bug Something isn't working label Apr 28, 2025
@nevans nevans force-pushed the sequence_set/fix-xor-should-not-modify-self branch from 6f4560d to 79fb1e6 Compare April 29, 2025 02:45
`set ^ other` and `set.xor other` are supposed to be safe transforms.
But, unfortunately, they modified the receiver if it wasn't frozen, and
crashed when it was!

The fix is trivial: convert `self` to `dup`.
@nevans nevans force-pushed the sequence_set/fix-xor-should-not-modify-self branch from 79fb1e6 to fa722c4 Compare April 29, 2025 02:53
@nevans nevans merged commit 59f259e into master Apr 29, 2025
37 checks passed
@nevans nevans deleted the sequence_set/fix-xor-should-not-modify-self branch April 29, 2025 02:57
@nevans nevans changed the title 🐛 SequenceSet#xor should not modify self 🐛 Fix SequenceSet#xor crash when set is frozen Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant