Skip to content

Fix edit algorithms deleting the wrong child via remove_child(<pointer>)#2025

Open
TroyHernandez wants to merge 3 commits into
AcademySoftwareFoundation:mainfrom
TroyHernandez:fix/edit-algo-remove-child-wrong-index
Open

Fix edit algorithms deleting the wrong child via remove_child(<pointer>)#2025
TroyHernandez wants to merge 3 commits into
AcademySoftwareFoundation:mainfrom
TroyHernandez:fix/edit-algo-remove-child-wrong-index

Conversation

@TroyHernandez

Copy link
Copy Markdown

Composition only declares remove_child(int index, ErrorStatus*), but overwrite() and insert() in editAlgorithm.cpp call it with a Composable* / Retainer:

composition->remove_child(transition);     // overwrite() and insert()
composition->remove_child(items.back());   // overwrite()

The pointer argument decays to bool (always true) → int(1), so these calls remove the child at index 1 (or, via adjusted_vector_index, the last child when size() == 1), not the item that was passed.

Impact

  • overwrite() over a multi-item span deletes the wrong clips: the partially-overwritten clip is removed while a fully-overwritten clip survives in place.
  • Transition removal in overwrite()/insert() removes index 1 instead of the intended transition.

Repro

Track A|M|B (each 5/8/5 frames), overwrite(X, track, [8, 18)) — a span that partially covers M and fully covers B to the track end:

before (buggy):  A[0+5] B[20+5] X[2+10]   # M removed, B kept — wrong
after  (fixed):  A[0+5] M[10+3] X[2+10]   # M trimmed, B removed — correct

Fix

Pass the already-computed (and bounds-checked) index for transitions, and index_of_child(items.back()) in the removal loop.

Tests

  • Adds test_edit_overwrite_partial_first_full_last, which fails before this change and passes after.
  • The existing test_editAlgorithm suite continues to pass.

I verified the fix and the regression test by building the library locally (the test fails on the unfixed tree, passes on the fixed tree).

Composition only declares `remove_child(int index, ErrorStatus*)`, but
`overwrite()` and `insert()` call it with a `Composable*` / `Retainer`:

    composition->remove_child(transition);     // overwrite() and insert()
    composition->remove_child(items.back());   // overwrite()

The pointer argument decays to `bool` (always true) -> `int(1)`, so these calls
remove the child at index 1 (or, via adjusted_vector_index, the last child when
size == 1), NOT the item that was passed. As a result:

- overwrite() over a multi-item span deletes the wrong clips: the
  partially-overwritten clip is removed while a fully-overwritten clip survives.
- transition removal in overwrite()/insert() removes index 1 instead of the
  transition.

Pass the already-computed (and bounds-checked) `index` for transitions, and the
index of `items.back()` in the removal loop.

Repro (overwrite A|M|B with X over a span that ends at the track end):
  before:  A[0+5] B[20+5] X[2+10]   (M removed, B kept -- wrong)
  after:   A[0+5] M[10+3] X[2+10]   (M trimmed, B removed -- correct)

Adds a regression test (fails before, passes after); the existing
test_editAlgorithm suite continues to pass.

Signed-off-by: Troy Hernandez <troy.hernandez@pm.me>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 7, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: TroyHernandez / name: Troy Hernandez (8680cd2)

@codecov-commenter

codecov-commenter commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.33%. Comparing base (9d3c3a1) to head (6670f49).

Files with missing lines Patch % Lines
src/opentimelineio/algo/editAlgorithm.cpp 0.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2025      +/-   ##
==========================================
- Coverage   84.33%   84.33%   -0.01%     
==========================================
  Files         181      181              
  Lines       13267    13268       +1     
  Branches     1214     1214              
==========================================
  Hits        11189    11189              
- Misses       1895     1896       +1     
  Partials      183      183              
Flag Coverage Δ
py-unittests 84.33% <20.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/opentimelineio/serializableObject.h 83.78% <100.00%> (ø)
src/opentimelineio/algo/editAlgorithm.cpp 0.00% <0.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d3c3a1...6670f49. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jminor

jminor commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Oh, good catch!

Would you mind adding explicit to the operator bool() on Retainer? I think that would have caused this error to be caught by the compiler & will help prevent folks using OTIO from falling into this same trap.

(cc @meshula to check this)

@jminor jminor requested a review from meshula June 10, 2026 05:55
…child-wrong-index

Signed-off-by: Troy Hernandez <troy.hernandez@pm.me>
Requested in PR review: the implicit Retainer -> bool -> int conversion
chain is what allowed remove_child(<Retainer>) to compile and silently
remove the child at index 1. Marking the conversion explicit turns that
mistake into a compile error, while contextual conversion keeps
if (retainer), &&, and friends working unchanged.

The library and all C++ tests build cleanly with no call-site changes
needed, and the full test suite passes.

Signed-off-by: Troy Hernandez <troy.hernandez@pm.me>
@TroyHernandez

Copy link
Copy Markdown
Author

Done in 6670f49 (also merged main to pick up #2020, which touches the same functions).

  • The library, all C++ tests, and the Python bindings compile with zero call-site changes; full CI matrix is green.
  • I verified the guard works: compiling the original bug pattern, composition->remove_child(some_retainer), now fails with invalid user-defined conversion from 'Retainer<Composable>' to 'int'.
  • For @meshula re: compatibility, the break surface is narrower than "explicit operator bool" usually implies. Since operator T*() is still implicit, boolean contexts (if (r), &&, !) and plain bool b = r; all still compile via the pointer conversion. The only thing explicit forbids is using bool as a bridge to another type (Retainer -> bool -> int), which is exactly the trap this PR fixes. I'd expect zero impact on correct downstream code.

@meshula meshula left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@meshula meshula left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank yo for this!!

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.

4 participants