Skip to content

Fix null pointer dereferences after dynamic_cast (rewritten)#2020

Open
jminor wants to merge 7 commits into
AcademySoftwareFoundation:mainfrom
jminor:fix-null-ptr-deref-no-llm
Open

Fix null pointer dereferences after dynamic_cast (rewritten)#2020
jminor wants to merge 7 commits into
AcademySoftwareFoundation:mainfrom
jminor:fix-null-ptr-deref-no-llm

Conversation

@jminor
Copy link
Copy Markdown
Collaborator

@jminor jminor commented May 1, 2026

Certain invalid OTIO object graphs may cause crashes due to code that assumes a dynamic_cast always returns a valid object. This PR introduces tests which demonstrate the issue and a fix to prevent the crash in those cases.

I made sure to write the tests first, ensure that they caused the crash (SEGFAULT) and then made the fix to each of the affected functions. I introduced a new ErrorStatus::CANNOT_CLONE_ITEM for this specific case. The code may also return ErrorStatus::TYPE_MISMATCH in a related edge case, but I was not able to create a scenario which triggers that case.

Note that the discovery of this issue was assisted by Claude Code Opus 4.6 and Opus 4.7, but all of the code in this PR was written by a human (me). This PR replaces #2017 which had LLM-generated code in it.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 1, 2026

Codecov Report

❌ Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.33%. Comparing base (6944f10) to head (7e8876a).

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

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2020      +/-   ##
==========================================
- Coverage   84.51%   84.33%   -0.18%     
==========================================
  Files         181      181              
  Lines       13239    13267      +28     
  Branches     1202     1214      +12     
==========================================
  Hits        11189    11189              
- Misses       1867     1895      +28     
  Partials      183      183              
Flag Coverage Δ
py-unittests 84.33% <0.00%> (-0.18%) ⬇️

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

Files with missing lines Coverage Δ
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 6944f10...7e8876a. Read the comment docs.

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

Copy link
Copy Markdown
Collaborator

@meshula meshula left a comment

Choose a reason for hiding this comment

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

This looks more rigorous than the initial fix.

Copy link
Copy Markdown
Contributor

@darbyjohnston darbyjohnston left a comment

Choose a reason for hiding this comment

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

Thanks, I think this is clearer about what is being tested than the previous PR. When we are happy with this one, try asking Claude to compare the two and see what it thinks about the changes.

Comment thread src/opentimelineio/algo/editAlgorithm.cpp Outdated
@jminor jminor force-pushed the fix-null-ptr-deref-no-llm branch from 9ea57a5 to 896b205 Compare June 5, 2026 04:56
jminor added 7 commits June 4, 2026 22:00
Signed-off-by: Joshua Minor <jminor@users.noreply.github.com>
Signed-off-by: Joshua Minor <jminor@users.noreply.github.com>
Signed-off-by: Joshua Minor <jminor@users.noreply.github.com>
Signed-off-by: Joshua Minor <jminor@users.noreply.github.com>
Signed-off-by: Joshua Minor <jminor@users.noreply.github.com>
Signed-off-by: Joshua Minor <jminor@users.noreply.github.com>
…NOT_CLONE_ITEM error status.

Signed-off-by: Joshua Minor <jminor@users.noreply.github.com>
@jminor jminor force-pushed the fix-null-ptr-deref-no-llm branch from 896b205 to 7e8876a Compare June 5, 2026 05:01
@jminor jminor requested a review from darbyjohnston June 5, 2026 05:10
TimeRange(RationalTime(0.0, 24.0), RationalTime(24.0, 24.0)));
big_clip->metadata()["cycle"] = big_clip;

SerializableObject::Retainer<Clip> small_clip = new Clip(
Copy link
Copy Markdown
Contributor

@darbyjohnston darbyjohnston Jun 5, 2026

Choose a reason for hiding this comment

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

It doesn't look like small_clip is being used in this test?

SerializableObject::Retainer<Track> track = new Track();
track->append_child(small_clip);
track->append_child(gap);
track->append_child(small_clip);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is adding the small_clip twice intentional?

TimeRange(RationalTime(0.0, 24.0), RationalTime(10.0, 24.0)) });
});

tests.add_test("regression: crash in slice", [] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but since the crash is fixed maybe the test name should change?

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