-
Notifications
You must be signed in to change notification settings - Fork 641
frames decoder fixes: avoid overflow, handle multiple frames per packet #5911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
frames decoder fixes: avoid overflow, handle multiple frames per packet #5911
Conversation
CI MESSAGE: [28009735]: BUILD STARTED |
6721d99
to
5de3818
Compare
CI MESSAGE: [28009735]: BUILD FAILED |
CI MESSAGE: [28017933]: BUILD STARTED |
CI MESSAGE: [28017933]: BUILD FAILED |
for (auto &[frame_id, i] : frame_ids) { | ||
auto out_frame_start = data + ptrdiff_t(i) * FrameSize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto out_frame_start = data + ptrdiff_t(i) * FrameSize(); | |
uint8_t *out_frame_start = data + ptrdiff_t(i) * FrameSize(); |
...since we assign it to explicitly typed last_out_frame_start...
@@ -603,20 +603,21 @@ void FramesDecoderBase::DecodeFramesImpl(uint8_t *data, | |||
DALI_ENFORCE(constant_frame != nullptr || boundary_type != boundary::BoundaryType::CONSTANT, | |||
make_string("Constant frame must be provided if boundary type is CONSTANT")); | |||
|
|||
int last_out_frame_idx = -1; | |||
uint8_t* last_out_frame_start = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit
uint8_t* last_out_frame_start = nullptr; | |
uint8_t *last_out_frame_start = nullptr; |
// Take pts of the currently decoded frame | ||
int current_pts = piped_pts_.front(); | ||
piped_pts_.pop(); | ||
if (current_pts_ == -1) { // if != -1, it's not the first frame from the packet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun fact: as far as I know, presentation timestamp (PTS) is quite arbitrary and can be negative, so it'd be better to use a more obviously incorrect value (AV_NOPTS_VALUE) or alternatively use optional<int64_t>
@@ -198,6 +198,7 @@ class DLL_PUBLIC FramesDecoderGpu : public FramesDecoderBase { | |||
std::vector<BufferedFrame> frame_buffer_; | |||
|
|||
std::queue<int> piped_pts_; | |||
int current_pts_ = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int current_pts_ = -1; | |
int64_t current_pts_ = AV_NOPTS_VALUE; |
This is - and always was - too small. Use int64_t.
@@ -198,6 +198,7 @@ class DLL_PUBLIC FramesDecoderGpu : public FramesDecoderBase { | |||
std::vector<BufferedFrame> frame_buffer_; | |||
|
|||
std::queue<int> piped_pts_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::queue<int> piped_pts_; | |
std::queue<int64_t> piped_pts_; |
Signed-off-by: Joaquin Anton Guirao <[email protected]>
Signed-off-by: Joaquin Anton Guirao <[email protected]>
Signed-off-by: Joaquin Anton Guirao <[email protected]>
7462101
to
0437dc1
Compare
Signed-off-by: Joaquin Anton Guirao <[email protected]>
!build |
CI MESSAGE: [28145200]: BUILD STARTED |
// if != AV_NOPTS_VALUE, it's not the first frame from the packet | ||
// first frame from this packet, pop it from the queue and remember it. | ||
// If there are no piped pts, use the last pts available (unexpected extra frame) | ||
if (!piped_pts_.empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what happens if we have 2 packets in the processing, and the first will produce two frames and the last only one. We will affiliate the first frame with first packet, and the second and third with the second packet.
CI MESSAGE: [28145200]: BUILD FAILED |
CI MESSAGE: [28145200]: BUILD PASSED |
…et (NVIDIA#5911) Fixes a potential overflow issue in frame pointer arithmetic by using ptrdiff_t for pointer calculations and adding bounds checking Improves handling of multiple frames per packet in the GPU decoder by properly managing the PTS (Presentation Time Stamp) queue Signed-off-by: Joaquin Anton Guirao <[email protected]> Signed-off-by: Marek Dabek <[email protected]>
Category:
Bug fix (non-breaking change which fixes an issue)
Description:
This PR addresses two critical issues in the frames decoder implementation:
ptrdiff_t
for pointer calculations and adding bounds checkingThe changes ensure more robust frame decoding by preventing memory access issues and correctly handling frame ordering when multiple frames are present in a single packet.
Additional information:
Affected modules and functionalities:
dali/operators/video/frames_decoder_base.cc
:dali/operators/video/frames_decoder_gpu.cc
:Key points relevant for the review:
frames_decoder_base.cc
are critical for preventing potential buffer overflowsframes_decoder_gpu.cc
ensure correct frame orderingTests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A