Commit e2dae1fa authored by Mike Scheutzow's avatar Mike Scheutzow Committed by Michael Niedermayer

Fix a buffer overflow in libx264 interface to x264 encoder. Previous code...

Fix a buffer overflow in libx264 interface to x264 encoder. Previous code ignored the compressed buffer size passed in. This change returns as many complete NALs as can fit in the buffer, and logs an error message.
Signed-off-by: 's avatarMike Scheutzow <mike.scheutzow@alcatel-lucent.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent cbf914cf
......@@ -96,9 +96,14 @@ static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size,
/* Write the SEI as part of the first frame. */
if (x4->sei_size > 0 && nnal > 0) {
if (x4->sei_size > size) {
av_log(ctx, AV_LOG_ERROR, "Error: nal buffer is too small\n");
return -1;
}
memcpy(p, x4->sei, x4->sei_size);
p += x4->sei_size;
x4->sei_size = 0;
// why is x4->sei not freed?
}
for (i = 0; i < nnal; i++){
......@@ -109,6 +114,11 @@ static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size,
memcpy(x4->sei, nals[i].p_payload, nals[i].i_payload);
continue;
}
if (nals[i].i_payload > (size - (p - buf))) {
// return only complete nals which fit in buf
av_log(ctx, AV_LOG_ERROR, "Error: nal buffer is too small\n");
break;
}
memcpy(p, nals[i].p_payload, nals[i].i_payload);
p += nals[i].i_payload;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment