From 4860625236475da20d0da954017e8c7fe412dea2 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 13 Apr 2012 14:37:47 -0700 Subject: [PATCH 1/6] swscale: fix off-by-one in second coefficient in bilinear filters. If coefficient A is 12-bits xixed-point number "X", then the other coefficient is (1 << 12) - X, not (1 << 12) - X - 1. --- libswscale/output.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libswscale/output.c b/libswscale/output.c index 5bc25fc35a..c0f9b367d3 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -353,7 +353,7 @@ yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2], { const int16_t *buf0 = buf[0], *buf1 = buf[1]; const uint8_t * const d128 = dither_8x8_220[y & 7]; - int yalpha1 = 4095 - yalpha; + int yalpha1 = 4096 - yalpha; int i; for (i = 0; i < dstW; i += 8) { @@ -505,8 +505,8 @@ yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2], const int16_t *buf0 = buf[0], *buf1 = buf[1], *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], *vbuf0 = vbuf[0], *vbuf1 = vbuf[1]; - int yalpha1 = 4095 - yalpha; - int uvalpha1 = 4095 - uvalpha; + int yalpha1 = 4096 - yalpha; + int uvalpha1 = 4096 - uvalpha; int i; for (i = 0; i < ((dstW + 1) >> 1); i++) { @@ -648,8 +648,8 @@ yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2], const int32_t *buf0 = buf[0], *buf1 = buf[1], *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], *vbuf0 = vbuf[0], *vbuf1 = vbuf[1]; - int yalpha1 = 4095 - yalpha; - int uvalpha1 = 4095 - uvalpha; + int yalpha1 = 4096 - yalpha; + int uvalpha1 = 4096 - uvalpha; int i; for (i = 0; i < ((dstW + 1) >> 1); i++) { @@ -995,8 +995,8 @@ yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2], *vbuf0 = vbuf[0], *vbuf1 = vbuf[1], *abuf0 = hasAlpha ? abuf[0] : NULL, *abuf1 = hasAlpha ? abuf[1] : NULL; - int yalpha1 = 4095 - yalpha; - int uvalpha1 = 4095 - uvalpha; + int yalpha1 = 4096 - yalpha; + int uvalpha1 = 4096 - uvalpha; int i; for (i = 0; i < ((dstW + 1) >> 1); i++) { From 7f77e9041a79fd05ed872ff9eeb06f109d30acb7 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 13 Apr 2012 14:42:21 -0700 Subject: [PATCH 2/6] swscale: clip before assigning tables in RGB output functions. --- libswscale/output.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/libswscale/output.c b/libswscale/output.c index c0f9b367d3..b58bda9213 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -1005,15 +1005,17 @@ yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2], int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19; int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19; int A1, A2; - const void *r = c->table_rV[V], - *g = (c->table_gU[U] + c->table_gV[V]), - *b = c->table_bU[U]; + const void *r, *g, *b; Y1 = av_clip_uint8(Y1); Y2 = av_clip_uint8(Y2); U = av_clip_uint8(U); V = av_clip_uint8(V); + r = c->table_rV[V]; + g = (c->table_gU[U] + c->table_gV[V]); + b = c->table_bU[U]; + if (hasAlpha) { A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19; A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19; @@ -1043,15 +1045,17 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, int U = ubuf0[i] >> 7; int V = vbuf0[i] >> 7; int A1, A2; - const void *r = c->table_rV[V], - *g = (c->table_gU[U] + c->table_gV[V]), - *b = c->table_bU[U]; + const void *r, *g, *b; Y1 = av_clip_uint8(Y1); Y2 = av_clip_uint8(Y2); U = av_clip_uint8(U); V = av_clip_uint8(V); + r = c->table_rV[V]; + g = (c->table_gU[U] + c->table_gV[V]); + b = c->table_bU[U]; + if (hasAlpha) { A1 = abuf0[i * 2 ] >> 7; A2 = abuf0[i * 2 + 1] >> 7; @@ -1070,15 +1074,17 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, int U = (ubuf0[i] + ubuf1[i]) >> 8; int V = (vbuf0[i] + vbuf1[i]) >> 8; int A1, A2; - const void *r = c->table_rV[V], - *g = (c->table_gU[U] + c->table_gV[V]), - *b = c->table_bU[U]; + const void *r, *g, *b; Y1 = av_clip_uint8(Y1); Y2 = av_clip_uint8(Y2); U = av_clip_uint8(U); V = av_clip_uint8(V); + r = c->table_rV[V]; + g = (c->table_gU[U] + c->table_gV[V]); + b = c->table_bU[U]; + if (hasAlpha) { A1 = abuf0[i * 2 ] >> 7; A2 = abuf0[i * 2 + 1] >> 7; From 4ebd422c04849a21a6bb2128a715979e8067e6a6 Mon Sep 17 00:00:00 2001 From: Dale Curtis Date: Thu, 12 Apr 2012 17:56:57 -0700 Subject: [PATCH 3/6] mov: fix leaking memory with multiple drefs. Instead of allocating over the original, free first. MOVStreamContext is zero initialized so no double free will occur. Same style as other fixes for the same problem in this file. Signed-off-by: Dale Curtis Signed-off-by: Luca Barbato --- libavformat/mov.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 046c030bcf..5787f1aeb0 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -387,6 +387,7 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) entries = avio_rb32(pb); if (entries >= UINT_MAX / sizeof(*sc->drefs)) return AVERROR_INVALIDDATA; + av_free(sc->drefs); sc->drefs = av_mallocz(entries * sizeof(*sc->drefs)); if (!sc->drefs) return AVERROR(ENOMEM); From c788782c7d2b9b6e5ffe8cfe0d8ed100283f2e6e Mon Sep 17 00:00:00 2001 From: Dale Curtis Date: Sat, 14 Apr 2012 17:48:42 -0700 Subject: [PATCH 4/6] mov: free memory on header parsing failure Call mov_read_close when mov_read_header fails. Signed-off-by: Luca Barbato --- libavformat/mov.c | 68 ++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 5787f1aeb0..11b4582766 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2594,6 +2594,39 @@ finish: avio_seek(sc->pb, cur_pos, SEEK_SET); } +static int mov_read_close(AVFormatContext *s) +{ + MOVContext *mov = s->priv_data; + int i, j; + + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + MOVStreamContext *sc = st->priv_data; + + av_freep(&sc->ctts_data); + for (j = 0; j < sc->drefs_count; j++) { + av_freep(&sc->drefs[j].path); + av_freep(&sc->drefs[j].dir); + } + av_freep(&sc->drefs); + if (sc->pb && sc->pb != s->pb) + avio_close(sc->pb); + } + + if (mov->dv_demux) { + for (i = 0; i < mov->dv_fctx->nb_streams; i++) { + av_freep(&mov->dv_fctx->streams[i]->codec); + av_freep(&mov->dv_fctx->streams[i]); + } + av_freep(&mov->dv_fctx); + av_freep(&mov->dv_demux); + } + + av_freep(&mov->trex_data); + + return 0; +} + static int mov_read_header(AVFormatContext *s) { MOVContext *mov = s->priv_data; @@ -2611,10 +2644,12 @@ static int mov_read_header(AVFormatContext *s) /* check MOV header */ if ((err = mov_read_default(mov, pb, atom)) < 0) { av_log(s, AV_LOG_ERROR, "error reading header: %d\n", err); + mov_read_close(s); return err; } if (!mov->found_moov) { av_log(s, AV_LOG_ERROR, "moov atom not found\n"); + mov_read_close(s); return AVERROR_INVALIDDATA; } av_dlog(mov->fc, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb)); @@ -2807,39 +2842,6 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti return 0; } -static int mov_read_close(AVFormatContext *s) -{ - MOVContext *mov = s->priv_data; - int i, j; - - for (i = 0; i < s->nb_streams; i++) { - AVStream *st = s->streams[i]; - MOVStreamContext *sc = st->priv_data; - - av_freep(&sc->ctts_data); - for (j = 0; j < sc->drefs_count; j++) { - av_freep(&sc->drefs[j].path); - av_freep(&sc->drefs[j].dir); - } - av_freep(&sc->drefs); - if (sc->pb && sc->pb != s->pb) - avio_close(sc->pb); - } - - if (mov->dv_demux) { - for (i = 0; i < mov->dv_fctx->nb_streams; i++) { - av_freep(&mov->dv_fctx->streams[i]->codec); - av_freep(&mov->dv_fctx->streams[i]); - } - av_freep(&mov->dv_fctx); - av_freep(&mov->dv_demux); - } - - av_freep(&mov->trex_data); - - return 0; -} - AVInputFormat ff_mov_demuxer = { .name = "mov,mp4,m4a,3gp,3g2,mj2", .long_name = NULL_IF_CONFIG_SMALL("QuickTime/MPEG-4/Motion JPEG 2000 format"), From 5096399df29ce91874165bdf22461b1c5020cda2 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Sat, 14 Apr 2012 17:26:58 -0400 Subject: [PATCH 5/6] utvideo: Remove unused variable 'src_size' Signed-off-by: Derek Buitenhuis --- libavcodec/utvideo.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libavcodec/utvideo.c b/libavcodec/utvideo.c index 95cea5f423..378a1f7c16 100644 --- a/libavcodec/utvideo.c +++ b/libavcodec/utvideo.c @@ -112,7 +112,7 @@ static int build_huff(const uint8_t *src, VLC *vlc, int *fsym) static int decode_plane(UtvideoContext *c, int plane_no, uint8_t *dst, int step, int stride, int width, int height, - const uint8_t *src, int src_size, int use_pred) + const uint8_t *src, int use_pred) { int i, j, slice, pix; int sstart, send; @@ -151,7 +151,6 @@ static int decode_plane(UtvideoContext *c, int plane_no, } src += 256; - src_size -= 256; send = 0; for (slice = 0; slice < c->slices; slice++) { @@ -431,8 +430,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac for (i = 0; i < c->planes; i++) { ret = decode_plane(c, i, c->pic.data[0] + rgb_order[i], c->planes, c->pic.linesize[0], avctx->width, avctx->height, - plane_start[i], plane_start[i + 1] - plane_start[i], - c->frame_pred == PRED_LEFT); + plane_start[i], c->frame_pred == PRED_LEFT); if (ret) return ret; if (c->frame_pred == PRED_MEDIAN) @@ -447,8 +445,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac for (i = 0; i < 3; i++) { ret = decode_plane(c, i, c->pic.data[i], 1, c->pic.linesize[i], avctx->width >> !!i, avctx->height >> !!i, - plane_start[i], plane_start[i + 1] - plane_start[i], - c->frame_pred == PRED_LEFT); + plane_start[i], c->frame_pred == PRED_LEFT); if (ret) return ret; if (c->frame_pred == PRED_MEDIAN) { @@ -469,8 +466,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac for (i = 0; i < 3; i++) { ret = decode_plane(c, i, c->pic.data[i], 1, c->pic.linesize[i], avctx->width >> !!i, avctx->height, - plane_start[i], plane_start[i + 1] - plane_start[i], - c->frame_pred == PRED_LEFT); + plane_start[i], c->frame_pred == PRED_LEFT); if (ret) return ret; if (c->frame_pred == PRED_MEDIAN) { From 3892e784f2225b32c87a5996347994f108fbd369 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sat, 14 Apr 2012 19:24:16 +0200 Subject: [PATCH 6/6] doc: Improve suggested Emacs settings for our coding style. Switch from changing global values to defining a separate C style and add appropriate settings for indenting assignments that span more than one line. --- doc/developer.texi | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/developer.texi b/doc/developer.texi index 046743fd62..a4fdf3a625 100644 --- a/doc/developer.texi +++ b/doc/developer.texi @@ -226,10 +226,16 @@ autocmd InsertEnter * match ForbiddenWhitespace /\t\|\s\+\%#\@@