aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Scheutzow <mike.scheutzow@alcatel-lucent.com>2011-09-26 10:57:53 -0400
committerMichael Niedermayer <michaelni@gmx.at>2011-10-01 20:32:25 +0200
commit7e362df304121003fda7705917d5e797b48a0920 (patch)
tree9434da2a618ce71f11c7a1cf23651b9304422897
parentbe1ae17ec0e03b494e0ab9f1eedefe83cebd7f4e (diff)
downloadffmpeg-7e362df304121003fda7705917d5e797b48a0920.tar.gz
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: Mike Scheutzow <mike.scheutzow@alcatel-lucent.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit e2dae1faa84ada5746ac2114de7eb68abd824131)
-rw-r--r--libavcodec/libx264.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index cc5b9837f8..bf542accdf 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -70,9 +70,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++){
@@ -83,6 +88,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;
}