libs: encoder: h265: fix possible integer overflow

Coverity scan bug:

Unintentional integer overflow. The expression's value may not be what
the programmer intended, because the expression is evaluated using a
narrow (i.e. few bits) integer type.

Cast operator to guint64 before computation to avoid narrowing.

merge with 3c5a6add
This commit is contained in:
Víctor Manuel Jáquez Leal 2017-08-08 16:33:44 +02:00
parent 4e27245f28
commit bd7716a739
2 changed files with 4 additions and 2 deletions

View file

@ -2479,7 +2479,7 @@ ensure_bitrate (GstVaapiEncoderH264 * encoder)
if (!encoder->use_dct8x8)
bits_per_mb += (bits_per_mb * 10) / 100;
factor = encoder->mb_width * encoder->mb_height * bits_per_mb;
factor = (guint64) encoder->mb_width * encoder->mb_height * bits_per_mb;
base_encoder->bitrate =
gst_util_uint64_scale (factor, GST_VAAPI_ENCODER_FPS_N (encoder),
GST_VAAPI_ENCODER_FPS_D (encoder)) / 1000;

View file

@ -1902,7 +1902,9 @@ ensure_bitrate (GstVaapiEncoderH265 * encoder)
/* FIXME: Provide better estimation */
/* Using a 1/6 compression ratio */
/* 12 bits per pixel for YUV420 */
guint64 factor = encoder->luma_width * encoder->luma_height * 12 / 6;
guint64 factor;
factor = (guint64) encoder->luma_width * encoder->luma_height * 12 / 6;
base_encoder->bitrate =
gst_util_uint64_scale (factor, GST_VAAPI_ENCODER_FPS_N (encoder),
GST_VAAPI_ENCODER_FPS_D (encoder)) / 1000;