[FFmpeg-cvslog] lavc/alac: Avoid allocating huge memory blocks for malicious alac input.

2017-11-04 Thread Carl Eugen Hoyos
ffmpeg | branch: master | Carl Eugen Hoyos  | Wed Nov  1 
15:14:22 2017 +0100| [3357b68bc02d855a92656d7a474b22adb32ca1a7] | committer: 
Carl Eugen Hoyos

lavc/alac: Avoid allocating huge memory blocks for malicious alac input.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3357b68bc02d855a92656d7a474b22adb32ca1a7
---

 libavcodec/alac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index d6bd21ba13..93cf198eea 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -524,7 +524,7 @@ static int alac_set_info(ALACContext *alac)
 
 alac->max_samples_per_frame = bytestream2_get_be32u(&gb);
 if (!alac->max_samples_per_frame ||
-alac->max_samples_per_frame > INT_MAX / sizeof(int32_t)) {
+alac->max_samples_per_frame > 4096 * 4096) {
 av_log(alac->avctx, AV_LOG_ERROR,
"max samples per frame invalid: %"PRIu32"\n",
alac->max_samples_per_frame);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] h264: Make Truncating SPS/PPS message debug.

2017-11-04 Thread Kieran Kunhya
ffmpeg | branch: master | Kieran Kunhya  | Wed Aug 30 14:38:46 
2017 +0100| [77748d12a01de6f290a9d3663a0b777d752ac5b7] | committer: Your Name

h264: Make Truncating SPS/PPS message debug.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=77748d12a01de6f290a9d3663a0b777d752ac5b7
---

 libavcodec/h264_ps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index b7d5f65d32..8d1ef831fa 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -348,7 +348,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, 
AVCodecContext *avctx,
 
 sps->data_size = gb->buffer_end - gb->buffer;
 if (sps->data_size > sizeof(sps->data)) {
-av_log(avctx, AV_LOG_WARNING, "Truncating likely oversized SPS\n");
+av_log(avctx, AV_LOG_DEBUG, "Truncating likely oversized SPS\n");
 sps->data_size = sizeof(sps->data);
 }
 memcpy(sps->data, gb->buffer, sps->data_size);
@@ -745,7 +745,7 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, 
AVCodecContext *avct
 
 pps->data_size = gb->buffer_end - gb->buffer;
 if (pps->data_size > sizeof(pps->data)) {
-av_log(avctx, AV_LOG_WARNING, "Truncating likely oversized PPS "
+av_log(avctx, AV_LOG_DEBUG, "Truncating likely oversized PPS "
"(%"SIZE_SPECIFIER" > %"SIZE_SPECIFIER")\n",
pps->data_size, sizeof(pps->data));
 pps->data_size = sizeof(pps->data);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] h2645_parse: Allocate a single buffer per packet

2017-11-04 Thread Kieran Kunhya
ffmpeg | branch: master | Kieran Kunhya  | Sat Nov  4 17:41:06 
2017 +| [03b82b3ab9883cef017e513c7d0b3b986b3b3e7b] | committer: Your Name

h2645_parse: Allocate a single buffer per packet

Drastically reduces memory usage on pathological streams.
Fixes ticket #6789

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=03b82b3ab9883cef017e513c7d0b3b986b3b3e7b
---

 libavcodec/h2645_parse.c | 21 -
 libavcodec/h2645_parse.h | 10 --
 libavcodec/h264_parser.c | 13 +
 libavcodec/qsvenc_hevc.c | 13 +
 4 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index 3fbbaf4d29..e6c40381b0 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -31,11 +31,10 @@
 #include "h2645_parse.h"
 
 int ff_h2645_extract_rbsp(const uint8_t *src, int length,
-  H2645NAL *nal, int small_padding)
+  H2645RBSP *rbsp, H2645NAL *nal, int small_padding)
 {
 int i, si, di;
 uint8_t *dst;
-int64_t padding = small_padding ? 0 : MAX_MBPAIR_SIZE;
 
 nal->skipped_bytes = 0;
 #define STARTCODE_TEST  \
@@ -92,11 +91,7 @@ int ff_h2645_extract_rbsp(const uint8_t *src, int length,
 } else if (i > length)
 i = length;
 
-av_fast_padded_malloc(&nal->rbsp_buffer, &nal->rbsp_buffer_size,
-  length + padding);
-if (!nal->rbsp_buffer)
-return AVERROR(ENOMEM);
-
+nal->rbsp_buffer = &rbsp->rbsp_buffer[rbsp->rbsp_buffer_size];
 dst = nal->rbsp_buffer;
 
 memcpy(dst, src, i);
@@ -145,6 +140,8 @@ nsc:
 nal->size = di;
 nal->raw_data = src;
 nal->raw_size = si;
+rbsp->rbsp_buffer_size += si;
+
 return si;
 }
 
@@ -270,9 +267,14 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t 
*buf, int length,
 GetByteContext bc;
 int consumed, ret = 0;
 int next_avc = is_nalff ? 0 : length;
+int64_t padding = small_padding ? 0 : MAX_MBPAIR_SIZE;
 
 bytestream2_init(&bc, buf, length);
+av_fast_padded_malloc(&pkt->rbsp.rbsp_buffer, 
&pkt->rbsp.rbsp_buffer_alloc_size, length + padding);
+if (!pkt->rbsp.rbsp_buffer)
+return AVERROR(ENOMEM);
 
+pkt->rbsp.rbsp_buffer_size = 0;
 pkt->nb_nals = 0;
 while (bytestream2_get_bytes_left(&bc) >= 4) {
 H2645NAL *nal;
@@ -341,7 +343,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t 
*buf, int length,
 }
 nal = &pkt->nals[pkt->nb_nals];
 
-consumed = ff_h2645_extract_rbsp(bc.buffer, extract_length, nal, 
small_padding);
+consumed = ff_h2645_extract_rbsp(bc.buffer, extract_length, 
&pkt->rbsp, nal, small_padding);
 if (consumed < 0)
 return consumed;
 
@@ -385,9 +387,10 @@ void ff_h2645_packet_uninit(H2645Packet *pkt)
 {
 int i;
 for (i = 0; i < pkt->nals_allocated; i++) {
-av_freep(&pkt->nals[i].rbsp_buffer);
 av_freep(&pkt->nals[i].skipped_bytes_pos);
 }
 av_freep(&pkt->nals);
 pkt->nals_allocated = 0;
+av_freep(&pkt->rbsp.rbsp_buffer);
+pkt->rbsp.rbsp_buffer_alloc_size = pkt->rbsp.rbsp_buffer_size = 0;
 }
diff --git a/libavcodec/h2645_parse.h b/libavcodec/h2645_parse.h
index 5f3e17a0f2..2e29ad26cb 100644
--- a/libavcodec/h2645_parse.h
+++ b/libavcodec/h2645_parse.h
@@ -30,7 +30,6 @@
 
 typedef struct H2645NAL {
 uint8_t *rbsp_buffer;
-int rbsp_buffer_size;
 
 int size;
 const uint8_t *data;
@@ -65,9 +64,16 @@ typedef struct H2645NAL {
 int ref_idc;
 } H2645NAL;
 
+typedef struct H2645RBSP {
+uint8_t *rbsp_buffer;
+int rbsp_buffer_alloc_size;
+int rbsp_buffer_size;
+} H2645RBSP;
+
 /* an input packet split into unescaped NAL units */
 typedef struct H2645Packet {
 H2645NAL *nals;
+H2645RBSP rbsp;
 int nb_nals;
 int nals_allocated;
 } H2645Packet;
@@ -75,7 +81,7 @@ typedef struct H2645Packet {
 /**
  * Extract the raw (unescaped) bitstream.
  */
-int ff_h2645_extract_rbsp(const uint8_t *src, int length,
+int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645RBSP *rbsp,
   H2645NAL *nal, int small_padding);
 
 /**
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index dd0a965af0..39f97e00a6 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -243,6 +243,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
   const uint8_t * const buf, int buf_size)
 {
 H264ParseContext *p = s->priv_data;
+H2645RBSP rbsp = { NULL };
 H2645NAL nal = { NULL };
 int buf_index, next_avc;
 unsigned int pps_id;
@@ -263,6 +264,10 @@ static inline int parse_nal_units(AVCodecParserContext *s,
 if (!buf_size)
 return 0;
 
+av_fast_padded_malloc(&rbsp.rbsp_buffer, &rbsp.rbsp_buffer_alloc_size, 
buf_size);
+if (!rbsp.rbsp_buffer)
+return AVERROR(ENOMEM);
+
 b

[FFmpeg-cvslog] vc2enc: Calculate average slice quantiser correctly

2017-11-04 Thread Kieran Kunhya
ffmpeg | branch: master | Kieran Kunhya  | Mon Jul 24 19:25:41 
2017 +0100| [626d200e76e15487cff20992256a55919432b0b3] | committer: Kieran 
Kunhya

vc2enc: Calculate average slice quantiser correctly

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=626d200e76e15487cff20992256a55919432b0b3
---

 libavcodec/vc2enc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
index 96e27d93ed..f7fb17b076 100644
--- a/libavcodec/vc2enc.c
+++ b/libavcodec/vc2enc.c
@@ -167,7 +167,7 @@ typedef struct VC2EncContext {
 int slice_max_bytes;
 int slice_min_bytes;
 int q_ceil;
-int q_avg;
+int64_t q_avg;
 
 /* Options */
 double tolerance;
@@ -755,7 +755,7 @@ static int calc_slice_sizes(VC2EncContext *s)
 for (i = 0; i < s->num_x*s->num_y; i++) {
 SliceArgs *args = &enc_args[i];
 total_bytes_needed += args->bytes;
-s->q_avg = (s->q_avg + args->quant_idx)/2;
+s->q_avg += args->quant_idx;
 }
 
 return total_bytes_needed;
@@ -1045,7 +1045,7 @@ static av_cold int vc2_encode_end(AVCodecContext *avctx)
 int i;
 VC2EncContext *s = avctx->priv_data;
 
-av_log(avctx, AV_LOG_INFO, "Qavg: %i\n", s->q_avg);
+av_log(avctx, AV_LOG_INFO, "Qavg: %f\n", (float)s->q_avg / 
(s->num_x*s->num_y));
 
 for (i = 0; i < 3; i++) {
 ff_vc2enc_free_transforms(&s->transform_args[i].t);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] ffplay: create the window and the renderer before starting playback

2017-11-04 Thread Marton Balint
ffmpeg | branch: master | Marton Balint  | Sat Oct 28 22:06:22 
2017 +0200| [84d31e2475c41b0a69a11c4cba54755d034bb341] | committer: Marton 
Balint

ffplay: create the window and the renderer before starting playback

Signed-off-by: Marton Balint 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=84d31e2475c41b0a69a11c4cba54755d034bb341
---

 fftools/ffplay.c | 67 +---
 1 file changed, 35 insertions(+), 32 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 8e88a77820..7f1971aae5 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -361,6 +361,7 @@ static AVPacket flush_pkt;
 
 static SDL_Window *window;
 static SDL_Renderer *renderer;
+static SDL_RendererInfo renderer_info = {0};
 
 static const struct TextureFormatEntry {
 enum AVPixelFormat format;
@@ -1320,38 +1321,15 @@ static int video_open(VideoState *is)
 h = default_height;
 }
 
-if (!window) {
-int flags = SDL_WINDOW_SHOWN;
-if (!window_title)
-window_title = input_filename;
-if (is_full_screen)
-flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
-if (borderless)
-flags |= SDL_WINDOW_BORDERLESS;
-else
-flags |= SDL_WINDOW_RESIZABLE;
-window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, 
SDL_WINDOWPOS_UNDEFINED, w, h, flags);
-SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
-if (window) {
-SDL_RendererInfo info;
-renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED 
| SDL_RENDERER_PRESENTVSYNC);
-if (!renderer) {
-av_log(NULL, AV_LOG_WARNING, "Failed to initialize a hardware 
accelerated renderer: %s\n", SDL_GetError());
-renderer = SDL_CreateRenderer(window, -1, 0);
-}
-if (renderer) {
-if (!SDL_GetRendererInfo(renderer, &info))
-av_log(NULL, AV_LOG_VERBOSE, "Initialized %s renderer.\n", 
info.name);
-}
-}
-} else {
-SDL_SetWindowSize(window, w, h);
-}
+if (!window_title)
+window_title = input_filename;
+SDL_SetWindowTitle(window, window_title);
 
-if (!window || !renderer) {
-av_log(NULL, AV_LOG_FATAL, "SDL: could not set video mode - 
exiting\n");
-do_exit(is);
-}
+SDL_SetWindowSize(window, w, h);
+SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, 
SDL_WINDOWPOS_CENTERED);
+if (is_full_screen)
+SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
+SDL_ShowWindow(window);
 
 is->width  = w;
 is->height = h;
@@ -1362,7 +1340,7 @@ static int video_open(VideoState *is)
 /* display the current picture, if any */
 static void video_display(VideoState *is)
 {
-if (!window)
+if (!is->width)
 video_open(is);
 
 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
@@ -3744,6 +3722,31 @@ int main(int argc, char **argv)
 av_init_packet(&flush_pkt);
 flush_pkt.data = (uint8_t *)&flush_pkt;
 
+if (!display_disable) {
+int flags = SDL_WINDOW_HIDDEN;
+if (borderless)
+flags |= SDL_WINDOW_BORDERLESS;
+else
+flags |= SDL_WINDOW_RESIZABLE;
+window = SDL_CreateWindow(program_name, SDL_WINDOWPOS_UNDEFINED, 
SDL_WINDOWPOS_UNDEFINED, default_width, default_height, flags);
+SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
+if (window) {
+renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED 
| SDL_RENDERER_PRESENTVSYNC);
+if (!renderer) {
+av_log(NULL, AV_LOG_WARNING, "Failed to initialize a hardware 
accelerated renderer: %s\n", SDL_GetError());
+renderer = SDL_CreateRenderer(window, -1, 0);
+}
+if (renderer) {
+if (!SDL_GetRendererInfo(renderer, &renderer_info))
+av_log(NULL, AV_LOG_VERBOSE, "Initialized %s renderer.\n", 
renderer_info.name);
+}
+}
+if (!window || !renderer) {
+av_log(NULL, AV_LOG_FATAL, "Failed to create window or renderer: 
%s", SDL_GetError());
+do_exit(NULL);
+}
+}
+
 is = stream_open(input_filename, file_iformat);
 if (!is) {
 av_log(NULL, AV_LOG_FATAL, "Failed to initialize VideoState!\n");

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] ffplay: only use hardware accelerated SDL texture formats

2017-11-04 Thread Marton Balint
ffmpeg | branch: master | Marton Balint  | Sat Oct 28 22:46:08 
2017 +0200| [415038f2bd321a3b41564d4e0c6c17d7a096c397] | committer: Marton 
Balint

ffplay: only use hardware accelerated SDL texture formats

Typically only a small subset of the SDL texture formats are supported directly
by the SDL renderer drivers, the rest is software emulated. It's better if
libswscale does the format conversion to a hardware-accelerated texture format
instead of SDL.

This should fix video render slowdowns with some texture formats after
3bd2228d05a05eab5f91ac00b01efac9cb07649b.

Signed-off-by: Marton Balint 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=415038f2bd321a3b41564d4e0c6c17d7a096c397
---

 fftools/ffplay.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 7f1971aae5..c264e92535 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -1828,10 +1828,18 @@ static int configure_video_filters(AVFilterGraph 
*graph, VideoState *is, const c
 AVCodecParameters *codecpar = is->video_st->codecpar;
 AVRational fr = av_guess_frame_rate(is->ic, is->video_st, NULL);
 AVDictionaryEntry *e = NULL;
-int i;
+int nb_pix_fmts = 0;
+int i, j;
 
-for (i = 0; i < FF_ARRAY_ELEMS(pix_fmts); i++)
-pix_fmts[i] = sdl_texture_format_map[i].format;
+for (i = 0; i < renderer_info.num_texture_formats; i++) {
+for (j = 0; j < FF_ARRAY_ELEMS(sdl_texture_format_map) - 1; j++) {
+if (renderer_info.texture_formats[i] == 
sdl_texture_format_map[j].texture_fmt) {
+pix_fmts[nb_pix_fmts++] = sdl_texture_format_map[j].format;
+break;
+}
+}
+}
+pix_fmts[nb_pix_fmts] = AV_PIX_FMT_NONE;
 
 while ((e = av_dict_get(sws_dict, "", e, AV_DICT_IGNORE_SUFFIX))) {
 if (!strcmp(e->key, "sws_flags")) {
@@ -3741,7 +3749,7 @@ int main(int argc, char **argv)
 av_log(NULL, AV_LOG_VERBOSE, "Initialized %s renderer.\n", 
renderer_info.name);
 }
 }
-if (!window || !renderer) {
+if (!window || !renderer || !renderer_info.num_texture_formats) {
 av_log(NULL, AV_LOG_FATAL, "Failed to create window or renderer: 
%s", SDL_GetError());
 do_exit(NULL);
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] Revert "vc2enc: Calculate average slice quantiser correctly"

2017-11-04 Thread Kieran Kunhya
ffmpeg | branch: master | Kieran Kunhya  | Sat Nov  4 18:31:59 
2017 +| [1358f7ddb3a0b3ebbf2c6100fb31c2c4788b7458] | committer: Kieran 
Kunhya

Revert "vc2enc: Calculate average slice quantiser correctly"

This reverts commit 626d200e76e15487cff20992256a55919432b0b3.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1358f7ddb3a0b3ebbf2c6100fb31c2c4788b7458
---

 libavcodec/vc2enc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
index f7fb17b076..96e27d93ed 100644
--- a/libavcodec/vc2enc.c
+++ b/libavcodec/vc2enc.c
@@ -167,7 +167,7 @@ typedef struct VC2EncContext {
 int slice_max_bytes;
 int slice_min_bytes;
 int q_ceil;
-int64_t q_avg;
+int q_avg;
 
 /* Options */
 double tolerance;
@@ -755,7 +755,7 @@ static int calc_slice_sizes(VC2EncContext *s)
 for (i = 0; i < s->num_x*s->num_y; i++) {
 SliceArgs *args = &enc_args[i];
 total_bytes_needed += args->bytes;
-s->q_avg += args->quant_idx;
+s->q_avg = (s->q_avg + args->quant_idx)/2;
 }
 
 return total_bytes_needed;
@@ -1045,7 +1045,7 @@ static av_cold int vc2_encode_end(AVCodecContext *avctx)
 int i;
 VC2EncContext *s = avctx->priv_data;
 
-av_log(avctx, AV_LOG_INFO, "Qavg: %f\n", (float)s->q_avg / 
(s->num_x*s->num_y));
+av_log(avctx, AV_LOG_INFO, "Qavg: %i\n", s->q_avg);
 
 for (i = 0; i < 3; i++) {
 ff_vc2enc_free_transforms(&s->transform_args[i].t);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/exr: fix undefined shift in pxr24_uncompress()

2017-11-04 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sat 
Nov  4 01:19:19 2017 +0100| [66f0c958bfd5475658b432d1af4d2e174b2dfcda] | 
committer: Michael Niedermayer

avcodec/exr: fix undefined shift in pxr24_uncompress()

Fixes: runtime error: left shift of 255 by 24 places cannot be represented in 
type 'int'
Fixes: 3787/clusterfuzz-testcase-minimized-5728764920070144

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=66f0c958bfd5475658b432d1af4d2e174b2dfcda
---

 libavcodec/exr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 0b755db3cb..b1ecde4ebd 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -855,7 +855,7 @@ static int pxr24_uncompress(EXRContext *s, const uint8_t 
*src,
 in = ptr[2] + td->xsize;
 
 for (j = 0; j < td->xsize; ++j) {
-uint32_t diff = (*(ptr[0]++) << 24) |
+uint32_t diff = ((unsigned)*(ptr[0]++) << 24) |
 (*(ptr[1]++) << 16) |
 (*(ptr[2]++) << 8);
 pixel += diff;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/mips: Improve hevc uni weighted 4 tap hz mc msa functions

2017-11-04 Thread Kaustubh Raste
ffmpeg | branch: master | Kaustubh Raste  | Fri Nov  
3 13:23:23 2017 +0530| [b9cd26f556f4ca0dfe71ffd75a7272782b324753] | committer: 
Michael Niedermayer

avcodec/mips: Improve hevc uni weighted 4 tap hz mc msa functions

Use global mask buffer for appropriate mask load.
Use immediate unsigned saturation for clip to max saving one vector register.
Remove unused macro.

Signed-off-by: Kaustubh Raste 
Reviewed-by: Manojkumar Bhosale 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b9cd26f556f4ca0dfe71ffd75a7272782b324753
---

 libavcodec/mips/hevc_mc_uniw_msa.c | 892 +++--
 1 file changed, 448 insertions(+), 444 deletions(-)

diff --git a/libavcodec/mips/hevc_mc_uniw_msa.c 
b/libavcodec/mips/hevc_mc_uniw_msa.c
index 0796b0aa7c..31fec7330e 100644
--- a/libavcodec/mips/hevc_mc_uniw_msa.c
+++ b/libavcodec/mips/hevc_mc_uniw_msa.c
@@ -29,19 +29,6 @@ static const uint8_t ff_hevc_mask_arr[16 * 2] 
__attribute__((aligned(0x40))) = {
 0, 1, 1, 2, 2, 3, 3, 4, 16, 17, 17, 18, 18, 19, 19, 20
 };
 
-#define HEVC_HV_UNIW_RND_CLIP4(in0, in1, in2, in3, wgt, offset, rnd,   \
-   out0, out1, out2, out3) \
-{  \
-MUL4(in0, wgt, in1, wgt, in2, wgt, in3, wgt, out0, out1, out2, out3);  \
-SRAR_W4_SW(out0, out1, out2, out3, rnd);   \
-ADD4(out0, offset, out1, offset, out2, offset, out3, offset,   \
- out0, out1, out2, out3);  \
-out0 = CLIP_SW_0_255(out0);\
-out1 = CLIP_SW_0_255(out1);\
-out2 = CLIP_SW_0_255(out2);\
-out3 = CLIP_SW_0_255(out3);\
-}
-
 #define HEVC_UNIW_RND_CLIP2(in0, in1, wgt, offset, rnd,  \
 out0_r, out1_r, out0_l, out1_l)  \
 {\
@@ -2382,19 +2369,19 @@ static void hevc_hz_uniwgt_4t_4x2_msa(uint8_t *src,
   uint8_t *dst,
   int32_t dst_stride,
   const int8_t *filter,
-  int32_t height,
   int32_t weight,
   int32_t offset,
   int32_t rnd_val)
 {
+v16u8 out;
 v8i16 filt0, filt1;
 v16i8 src0, src1, vec0, vec1;
 v16i8 mask1;
 v8i16 dst0;
 v4i32 dst0_r, dst0_l;
-v8i16 filter_vec, const_vec;
-v4i32 weight_vec, offset_vec, rnd_vec;
-v16i8 mask0 = { 0, 1, 1, 2, 2, 3, 3, 4, 16, 17, 17, 18, 18, 19, 19, 20 };
+v8i16 filter_vec, weight_vec_h, offset_vec, denom_vec;
+v4i32 weight_vec, rnd_vec;
+v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[16]);
 
 src -= 1;
 
@@ -2405,29 +2392,33 @@ static void hevc_hz_uniwgt_4t_4x2_msa(uint8_t *src,
 
 weight = weight & 0x;
 
-const_vec = __msa_ldi_h(128);
-const_vec <<= 6;
-
 weight_vec = __msa_fill_w(weight);
-offset_vec = __msa_fill_w(offset);
 rnd_vec = __msa_fill_w(rnd_val);
 
+weight *= 128;
+rnd_val -= 6;
+
+weight_vec_h = __msa_fill_h(weight);
+offset_vec = __msa_fill_h(offset);
+denom_vec = __msa_fill_h(rnd_val);
+
+weight_vec_h = __msa_srar_h(weight_vec_h, denom_vec);
+offset_vec = __msa_adds_s_h(offset_vec, weight_vec_h);
+
 LD_SB2(src, src_stride, src0, src1);
 XORI_B2_128_SB(src0, src1);
 
 VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, vec0, vec1);
-dst0 = const_vec;
-DPADD_SB2_SH(vec0, vec1, filt0, filt1, dst0, dst0);
+dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
 
 ILVRL_H2_SW(dst0, dst0, dst0_r, dst0_l);
 DOTP_SH2_SW(dst0_r, dst0_l, weight_vec, weight_vec, dst0_r, dst0_l);
 SRAR_W2_SW(dst0_r, dst0_l, rnd_vec);
-ADD2(dst0_r, offset_vec, dst0_l, offset_vec, dst0_r, dst0_l);
-dst0_r = CLIP_SW_0_255(dst0_r);
-dst0_l = CLIP_SW_0_255(dst0_l);
-
-HEVC_PCK_SW_SB2(dst0_l, dst0_r, dst0_r);
-ST4x2_UB(dst0_r, dst, dst_stride);
+dst0 = __msa_pckev_h((v8i16) dst0_l, (v8i16) dst0_r);
+dst0 = __msa_adds_s_h(dst0, offset_vec);
+dst0 = CLIP_SH_0_255_MAX_SATU(dst0);
+out = (v16u8) __msa_pckev_b((v16i8) dst0, (v16i8) dst0);
+ST4x2_UB(out, dst, dst_stride);
 dst += (4 * dst_stride);
 }
 
@@ -2436,19 +2427,18 @@ static void hevc_hz_uniwgt_4t_4x4_msa(uint8_t *src,
   uint8_t *dst,
   int32_t dst_stride,
   const int8_t *filter,
-  int32_t height,
   int32_t weight,
  

[FFmpeg-cvslog] ffmpeg.c: fix calculation of input file duration in seek_to_start()

2017-11-04 Thread Peter Große
ffmpeg | branch: master | Peter Große  | Sun Oct 29 12:08:05 
2017 +0100| [3ddb887c88483ce089b29a30d0d0aa574c8cdc66] | committer: Michael 
Niedermayer

ffmpeg.c: fix calculation of input file duration in seek_to_start()

Fixes looping files without audio or when using stream_copy, where
ist->nb_samples is not set since no decoding is done.

This fixes ticket #5719 and also fixes an endless loop with the sample
in ticket #6139.

Signed-off-by: Peter Große 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3ddb887c88483ce089b29a30d0d0aa574c8cdc66
---

 fftools/ffmpeg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 286d898b12..65dbe93626 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4150,9 +4150,9 @@ static int seek_to_start(InputFile *ifile, 
AVFormatContext *is)
 continue;
 } else {
 if (ist->framerate.num) {
-duration = av_rescale_q(1, ist->framerate, ist->st->time_base);
+duration = av_rescale_q(1, av_inv_q(ist->framerate), 
ist->st->time_base);
 } else if (ist->st->avg_frame_rate.num) {
-duration = av_rescale_q(1, ist->st->avg_frame_rate, 
ist->st->time_base);
+duration = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), 
ist->st->time_base);
 } else duration = 1;
 }
 if (!ifile->duration)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/xan: Check for bitstream end in xan_huffman_decode()

2017-11-04 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Fri 
Nov  3 17:48:29 2017 +0100| [4b51437dccd62fc5491280db44e3c21b44aeeb3f] | 
committer: Michael Niedermayer

avcodec/xan: Check for bitstream end in xan_huffman_decode()

Fixes: Timeout
Fixes: 3707/clusterfuzz-testcase-6465922706440192

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4b51437dccd62fc5491280db44e3c21b44aeeb3f
---

 libavcodec/xan.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/xan.c b/libavcodec/xan.c
index 8b4ec82405..1ccf164847 100644
--- a/libavcodec/xan.c
+++ b/libavcodec/xan.c
@@ -131,7 +131,10 @@ static int xan_huffman_decode(uint8_t *dest, int dest_len,
 return ret;
 
 while (val != 0x16) {
-unsigned idx = val - 0x17 + get_bits1(&gb) * byte;
+unsigned idx;
+if (get_bits_left(&gb) < 1)
+return AVERROR_INVALIDDATA;
+idx = val - 0x17 + get_bits1(&gb) * byte;
 if (idx >= 2 * byte)
 return AVERROR_INVALIDDATA;
 val = src[idx];

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/mips: Improve hevc uni 4 tap hz and vt mc msa functions

2017-11-04 Thread Kaustubh Raste
ffmpeg | branch: master | Kaustubh Raste  | Fri Nov  
3 12:47:58 2017 +0530| [1e7e9fbb03c36b51ca7999ff2450afd64e789011] | committer: 
Michael Niedermayer

avcodec/mips: Improve hevc uni 4 tap hz and vt mc msa functions

Use global mask buffer for appropriate mask load.

Signed-off-by: Kaustubh Raste 
Reviewed-by: Manojkumar Bhosale 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1e7e9fbb03c36b51ca7999ff2450afd64e789011
---

 libavcodec/mips/hevc_mc_uni_msa.c | 509 --
 1 file changed, 274 insertions(+), 235 deletions(-)

diff --git a/libavcodec/mips/hevc_mc_uni_msa.c 
b/libavcodec/mips/hevc_mc_uni_msa.c
index 7d24858ba7..993dad06aa 100644
--- a/libavcodec/mips/hevc_mc_uni_msa.c
+++ b/libavcodec/mips/hevc_mc_uni_msa.c
@@ -1947,7 +1947,7 @@ static void common_hz_4t_4x2_msa(uint8_t *src, int32_t 
src_stride,
 v16u8 out;
 v8i16 filt, res0;
 
-mask0 = LD_SB(&mc_filt_mask_arr[16]);
+mask0 = LD_SB(&ff_hevc_mask_arr[16]);
 src -= 1;
 
 /* rearranging filter */
@@ -1959,7 +1959,7 @@ static void common_hz_4t_4x2_msa(uint8_t *src, int32_t 
src_stride,
 LD_SB2(src, src_stride, src0, src1);
 XORI_B2_128_SB(src0, src1);
 VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, vec0, vec1);
-res0 = FILT_4TAP_DPADD_S_H(vec0, vec1, filt0, filt1);
+res0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
 res0 = __msa_srari_h(res0, 6);
 res0 = __msa_sat_s_h(res0, 7);
 out = PCKEV_XORI128_UB(res0, res0);
@@ -1974,7 +1974,7 @@ static void common_hz_4t_4x4_msa(uint8_t *src, int32_t 
src_stride,
 v8i16 filt, out0, out1;
 v16u8 out;
 
-mask0 = LD_SB(&mc_filt_mask_arr[16]);
+mask0 = LD_SB(&ff_hevc_mask_arr[16]);
 src -= 1;
 
 /* rearranging filter */
@@ -2001,7 +2001,7 @@ static void common_hz_4t_4x8_msa(uint8_t *src, int32_t 
src_stride,
 v16u8 out;
 v8i16 filt, out0, out1, out2, out3;
 
-mask0 = LD_SB(&mc_filt_mask_arr[16]);
+mask0 = LD_SB(&ff_hevc_mask_arr[16]);
 src -= 1;
 
 /* rearranging filter */
@@ -2038,7 +2038,7 @@ static void common_hz_4t_4x16_msa(uint8_t *src, int32_t 
src_stride,
 v16u8 out;
 v8i16 filt, out0, out1, out2, out3;
 
-mask0 = LD_SB(&mc_filt_mask_arr[16]);
+mask0 = LD_SB(&ff_hevc_mask_arr[16]);
 src -= 1;
 
 /* rearranging filter */
@@ -2098,12 +2098,11 @@ static void common_hz_4t_6w_msa(uint8_t *src, int32_t 
src_stride,
 uint8_t *dst, int32_t dst_stride,
 const int8_t *filter, int32_t height)
 {
-uint32_t loop_cnt;
 v16i8 src0, src1, src2, src3, filt0, filt1, mask0, mask1;
 v16u8 out4, out5;
 v8i16 filt, out0, out1, out2, out3;
 
-mask0 = LD_SB(&mc_filt_mask_arr[0]);
+mask0 = LD_SB(&ff_hevc_mask_arr[0]);
 src -= 1;
 
 /* rearranging filter */
@@ -2112,21 +2111,31 @@ static void common_hz_4t_6w_msa(uint8_t *src, int32_t 
src_stride,
 
 mask1 = mask0 + 2;
 
-for (loop_cnt = (height >> 2); loop_cnt--;) {
-LD_SB4(src, src_stride, src0, src1, src2, src3);
-src += (4 * src_stride);
+LD_SB4(src, src_stride, src0, src1, src2, src3);
+src += (4 * src_stride);
 
-XORI_B4_128_SB(src0, src1, src2, src3);
-HORIZ_4TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, filt0,
-   filt1, out0, out1, out2, out3);
-SRARI_H4_SH(out0, out1, out2, out3, 6);
-SAT_SH4_SH(out0, out1, out2, out3, 7);
+XORI_B4_128_SB(src0, src1, src2, src3);
+HORIZ_4TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, filt0,
+   filt1, out0, out1, out2, out3);
+SRARI_H4_SH(out0, out1, out2, out3, 6);
+SAT_SH4_SH(out0, out1, out2, out3, 7);
+out4 = PCKEV_XORI128_UB(out0, out1);
+out5 = PCKEV_XORI128_UB(out2, out3);
+ST6x4_UB(out4, out5, dst, dst_stride);
+dst += (4 * dst_stride);
 
-out4 = PCKEV_XORI128_UB(out0, out1);
-out5 = PCKEV_XORI128_UB(out2, out3);
-ST6x4_UB(out4, out5, dst, dst_stride);
-dst += (4 * dst_stride);
-}
+LD_SB4(src, src_stride, src0, src1, src2, src3);
+src += (4 * src_stride);
+
+XORI_B4_128_SB(src0, src1, src2, src3);
+HORIZ_4TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, filt0,
+   filt1, out0, out1, out2, out3);
+SRARI_H4_SH(out0, out1, out2, out3, 6);
+SAT_SH4_SH(out0, out1, out2, out3, 7);
+out4 = PCKEV_XORI128_UB(out0, out1);
+out5 = PCKEV_XORI128_UB(out2, out3);
+ST6x4_UB(out4, out5, dst, dst_stride);
+dst += (4 * dst_stride);
 }
 
 static void common_hz_4t_8x2mult_msa(uint8_t *src, int32_t src_stride,
@@ -2138,7 +2147,7 @@ static void common_hz_4t_8x2mult_msa(uint8_t *src, 
int32_t src_stride,
 v16u8 out;
 v8i16 filt, vec0, vec1, vec2, vec3;
 
-mask0 = LD_SB(&mc_filt_mask_arr[0]);
+mask0 = LD_SB(&ff_hevc_mask_arr[0]);
 src -= 1;
 
  

[FFmpeg-cvslog] ffmpeg.c: fix code style in seek_to_start

2017-11-04 Thread Peter Große
ffmpeg | branch: master | Peter Große  | Sun Oct 29 15:07:12 
2017 +0100| [0ae1f6ddeb350d767a4860e1dcffea9cebe9917c] | committer: Michael 
Niedermayer

ffmpeg.c: fix code style in seek_to_start

Signed-off-by: Peter Große 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0ae1f6ddeb350d767a4860e1dcffea9cebe9917c
---

 fftools/ffmpeg.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 65dbe93626..679929cfc4 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4146,14 +4146,17 @@ static int seek_to_start(InputFile *ifile, 
AVFormatContext *is)
 AVRational sample_rate = {1, avctx->sample_rate};
 
 duration = av_rescale_q(ist->nb_samples, sample_rate, 
ist->st->time_base);
-} else
+} else {
 continue;
+}
 } else {
 if (ist->framerate.num) {
 duration = av_rescale_q(1, av_inv_q(ist->framerate), 
ist->st->time_base);
 } else if (ist->st->avg_frame_rate.num) {
 duration = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), 
ist->st->time_base);
-} else duration = 1;
+} else {
+duration = 1;
+}
 }
 if (!ifile->duration)
 ifile->time_base = ist->st->time_base;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog