Skip to content

Commit 341ab11

Browse files
ondrejmirtesclaude
andcommitted
Separate optional keys after taking the snapshot in makeOffsetRequired()
The snapshot was taken after separating, so it shared the table the loop deletes from: the deletes went into a table of refcount 2 that was also being iterated. Only the current entry is ever deleted, so the result was right, but the write violated copy-on-write and trips HT_ASSERT_RC1 on debug PHP builds. Taking the snapshot first makes separate() give the deletes their own table, at the same one duplication as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EKX5yrrUnnbeRtc2oURC2u
1 parent c264536 commit 341ab11

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎turbo-ext/src/ConstantArrayType.cpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5177,9 +5177,11 @@ class ConstantArrayType
51775177

51785178
zv::Val keyValueZv = keyValue(keyType);
51795179
if (UNEXPECTED(keyValueZv.isUndef())) return zv::Val();
5180-
optionalKeysCopy.separate();
5181-
/* iterated over a snapshot: the twin's foreach reads a copy */
5180+
/* iterated over a snapshot: the twin's foreach reads a copy;
5181+
* taken before separating, so the deletes below go into a table
5182+
* of their own */
51825183
zv::Arr snapshot = zv::Arr::copyOfTable(optionalKeysCopy.table());
5184+
optionalKeysCopy.separate();
51835185
for (zv::ArrayEntry optionalEntry : snapshot.arrRef()) {
51845186
zval *key = optionalEntry.value().deref().raw();
51855187
bool keep = Z_TYPE_P(key) != IS_LONG || i != Z_LVAL_P(key);

0 commit comments

Comments
 (0)