summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2017-08-08 16:33:44 +0200
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2017-08-24 13:04:22 +0200
commit136bbc7624f8f4470148e734ff7dcbed95ea0de8 (patch)
tree87161f87bfbfab2a4865c52058ae01ba982066ea
parentaafa44a74bff548792b1af28ba4b8d672f3600e6 (diff)
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
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_h264.c2
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_h265.c6
2 files changed, 5 insertions, 3 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
index 16e5b438..d9bd7978 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
@@ -2325,7 +2325,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;
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c
index f49121ce..6457de00 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c
@@ -1880,8 +1880,10 @@ ensure_bitrate (GstVaapiEncoderH265 * encoder)
if (!base_encoder->bitrate) {
/* Fixme: Provide better estimation */
/* Using a 1/6 compression ratio */
- /* 12 bits per pixel fro yuv420 */
- guint64 factor = encoder->luma_width * encoder->luma_height * 12 / 6;
+ /* 12 bits per pixel for YUV420 */
+ 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;