Skip to content

fix(rocdecode): do not write to a popped frame in ffmpeg_video_dec - #14891

Merged
jeffqjiangNew merged 1 commit into
ROCm:developfrom
randomizedcoder:fix/rocdecode-ffmpeg-pop-back
Nov 3, 2026
Merged

jeffqjiangNew merged 1 commit into
ROCm:developfrom
randomizedcoder:fix/rocdecode-ffmpeg-pop-back

Conversation

@randomizedcoder

Copy link
Copy Markdown
Contributor

Motivation

FFMpegVideoDecoder::ReconfigureDecoder() writes through p_frame after vp_frames_.pop_back() removes the element it points to. cppcheck 2.18.3 reports this as invalidContainer.

Technical Details

Remove the write after pop_back() and pop each frame after optional buffer cleanup. This also ensures a null frame_ptr cannot prevent the loop from progressing. The cleanup order matches utils/rocvideodecode/roc_video_dec.cpp.

Issue Tracking

Closes #14890

Test Plan

Build with FFmpeg/HIP and exercise decoder reconfiguration with buffered frames.

Test Result

Source review and git diff --check passed. No FFmpeg/HIP build or runtime test was run locally. No CI results are available on this fork draft; upstream build/runtime validation remains pending.

FFMpegVideoDecoder::ReconfigureDecoder() had two bugs in its frame cleanup
loop:

- It called vp_frames_.pop_back() and then wrote p_frame->frame_ptr =
  nullptr. p_frame points to the element that pop_back() just removed, so
  the write uses a destroyed object.
- pop_back() was inside if (p_frame->frame_ptr). A frame with a null
  frame_ptr was never popped, so while (!vp_frames_.empty()) never ended
  and the decoder hung while holding mtx_vp_frame_.

Pop every frame after the optional free, and drop the write, like the same
loop in utils/rocvideodecode/roc_video_dec.cpp.

Found by cppcheck 2.18.3 (invalidContainer).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SbyZduM5A6iscMiP5UPGfb
@therock-pr-bot

therock-pr-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

✅ All Policy Checks Passed

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ⚠️ Warning Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/rocdecode/utils/ffmpegvideodecode/ffmpeg_video_dec.cpp; no test file found
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —

🎉 All policy checks passed!

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

Copilot AI left a comment

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.

🟢 Approval recommended

There are no active review issues for the decoder frame-cleanup change.

No open issues 🎉

What changed in this PR

Fixes frame cleanup during FFmpeg decoder reconfiguration in rocdecode, addressing the invalid access reported in #14890.

Changes:

  • Removes the write through p_frame after its vector element has been removed.
  • Pops each frame after optional buffer cleanup, ensuring null frame pointers cannot stall the loop.
File Description
projects/​rocdecode/​utils/​ffmpegvideodecode/​ffmpeg_video_dec.cpp Corrects frame cleanup order in ReconfigureDecoder().

Review effort: Balanced

@jeffqjiangNew
jeffqjiangNew merged commit bfe7697 into ROCm:develop Nov 3, 2026
81 of 87 checks passed
systems-assistant Bot pushed a commit to ROCm/rocDecode that referenced this pull request Nov 3, 2026
 ffmpeg_video_dec (#14891)

## Motivation

`FFMpegVideoDecoder::ReconfigureDecoder()` writes through `p_frame`
after `vp_frames_.pop_back()` removes the element it points to. cppcheck
2.18.3 reports this as `invalidContainer`.

## Technical Details

Remove the write after `pop_back()` and pop each frame after optional
buffer cleanup. This also ensures a null `frame_ptr` cannot prevent the
loop from progressing. The cleanup order matches
`utils/rocvideodecode/roc_video_dec.cpp`.

## Issue Tracking

Closes #14890

## Test Plan

Build with FFmpeg/HIP and exercise decoder reconfiguration with buffered
frames.

## Test Result

Source review and `git diff --check` passed. No FFmpeg/HIP build or
runtime test was run locally. No CI results are available on this fork
draft; upstream build/runtime validation remains pending.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
[rocm-systems] ROCm/rocm-systems#14891 (commit bfe7697)
@systems-assistant

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rocdecode: ffmpeg_video_dec writes to a frame after pop_back()

4 participants