Skip to content

Commit

Permalink
Fixed buffer overflow when using Video Toolbox (#3738)
Browse files Browse the repository at this point in the history
  • Loading branch information
sauwming authored Oct 13, 2023
1 parent 5c5b328 commit 6aa5349
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pjmedia/src/pjmedia-codec/vid_toolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static pj_status_t vtool_codec_decode(pjmedia_vid_codec *codec,
pj_uint8_t *dec_buf;
unsigned dec_buf_size;
CMFormatDescriptionRef dec_format;
OSStatus dec_status;
OSStatus dec_status;

unsigned dec_sps_size;
unsigned dec_pps_size;
Expand Down Expand Up @@ -1042,7 +1042,7 @@ static void decode_cb(void *decompressionOutputRefCon,
CMTime presentationDuration)
{
struct vtool_codec_data *vtool_data;
pj_size_t width, height, len;
pj_size_t width, height, len = 0;

/* This callback can be called from another, unregistered thread.
* So do not call pjlib functions here.
Expand All @@ -1068,7 +1068,12 @@ static void decode_cb(void *decompressionOutputRefCon,
vtool_data->dec_fmt_change = PJ_FALSE;
}

len = process_i420(imageBuffer, (pj_uint8_t *)vtool_data->dec_frame->buf);
if (vtool_data->dec_frame->size >= width * height * 3 / 2) {
len = process_i420(imageBuffer,
(pj_uint8_t *)vtool_data->dec_frame->buf);
} else {
vtool_data->dec_status = (OSStatus)PJMEDIA_CODEC_EFRMTOOSHORT;
}
vtool_data->dec_frame->size = len;

CVPixelBufferUnlockBaseAddress(imageBuffer,0);
Expand Down Expand Up @@ -1308,6 +1313,7 @@ static pj_status_t vtool_codec_decode(pjmedia_vid_codec *codec,

if (ret == noErr) {
vtool_data->dec_frame = output;
vtool_data->dec_frame->size = out_size;
ret = VTDecompressionSessionDecodeFrame(
vtool_data->dec, sample_buf, 0,
NULL, NULL);
Expand Down Expand Up @@ -1345,8 +1351,9 @@ static pj_status_t vtool_codec_decode(pjmedia_vid_codec *codec,
}

if ((ret != noErr) || (vtool_data->dec_status != noErr)) {
char *ret_err = (ret != noErr)?"decode err":"cb err";
OSStatus err_code = (ret != noErr)?ret:vtool_data->dec_status;
char *ret_err = (ret != noErr)?"decode err":"cb err";
OSStatus err_code = (ret != noErr)? ret:
vtool_data->dec_status;

PJ_LOG(5,(THIS_FILE, "Failed to decode frame %d of size "
"%d %s:%d", nalu_type, frm_size, ret_err,
Expand Down

0 comments on commit 6aa5349

Please sign in to comment.