Skip to content

Commit

Permalink
h264: Handle over-sized frames
Browse files Browse the repository at this point in the history
Over-sized frames from the server need to be handled to avoid out-of-bounds
memory access.
  • Loading branch information
any1 committed Jul 24, 2024
1 parent 160acd2 commit 27d0051
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion common/rfb/H264LibavDecoderContext.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@ void H264LibavDecoderContext::decode(const uint8_t* h264_in_buffer,
pb->getBuffer(rect, &stride);
int dst_linesize = rect.width() * pb->getPF().bpp / 8;

sws_scale(sws, frame->data, frame->linesize, 0, frame->height, &swsBuffer, &dst_linesize);
// The server may send a frame with a height greater than that of the rect,
// but we don't want to write outside of the rect.
// The server may choose to do this due to hardware encoder constraints.
int height = std::min(rect.height(), frame->height);

sws_scale(sws, frame->data, frame->linesize, 0, height, &swsBuffer,
&dst_linesize);

pb->imageRect(rect, swsBuffer);
}

0 comments on commit 27d0051

Please sign in to comment.