Skip to content

Commit a0b839d

Browse files
committed
[Rope] Fix copy-on-write violation in Rope.join
Rope.join has a logic error where it fails to properly ensure uniqueness of child node references before zipping the two b-trees together. rdar://128450202
1 parent 6c31865 commit a0b839d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Sources/RopeModule/Rope/Operations/Rope+Join.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ extension Rope {
3939
var left = left.root
4040
var right = right.root
4141

42-
left.ensureUnique()
43-
right.ensureUnique()
44-
4542
if left.height >= right.height {
4643
let r = left._graftBack(&right)
4744
guard let remainder = r.remainder else { return Self(root: left) }
@@ -64,6 +61,10 @@ extension Rope._Node {
6461
_ scion: inout Self
6562
) -> (remainder: Self?, delta: Summary) {
6663
assert(self.height >= scion.height)
64+
65+
self.ensureUnique()
66+
scion.ensureUnique()
67+
6768
guard self.height > scion.height else {
6869
assert(self.height == scion.height)
6970
let d = scion.summary
@@ -99,6 +100,10 @@ extension Rope._Node {
99100
_ scion: inout Self
100101
) -> (remainder: Self?, delta: Summary) {
101102
assert(self.height >= scion.height)
103+
104+
self.ensureUnique()
105+
scion.ensureUnique()
106+
102107
guard self.height > scion.height else {
103108
assert(self.height == scion.height)
104109
let origSum = self.summary

0 commit comments

Comments
 (0)