Skip to content

Conversation

@nevans
Copy link
Collaborator

@nevansnevans 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).

@nevansnevans changed the base branch from sequence_set/fix-slice-inconsistent-frozen to masterApril 28, 2025 22:55
@nevansnevans added the bug Something isn't working label Apr 28, 2025
@nevansnevansforce-pushed the sequence_set/fix-xor-should-not-modify-self branch from 6f4560d to 79fb1e6CompareApril 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`.
@nevansnevansforce-pushed the sequence_set/fix-xor-should-not-modify-self branch from 79fb1e6 to fa722c4CompareApril 29, 2025 02:53
@nevansnevans merged commit 59f259e into masterApr 29, 2025
37 checks passed
@nevansnevans deleted the sequence_set/fix-xor-should-not-modify-self branch April 29, 2025 02:57
@nevansnevans changed the title 🐛 SequenceSet#xor should not modify self🐛 Fix SequenceSet#xor crash when set is frozenApr 29, 2025
@nevansnevans added the sequence-set Any code the IMAP `sequence-set` data type or grammar rule, especially the SequenceSet class. label Dec 10, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workingsequence-setAny code the IMAP `sequence-set` data type or grammar rule, especially the SequenceSet class.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@nevans