[FFmpeg-devel] [PATCH] dvbsubdec: fix division by zero in compute_default_clut

Andreas Cadhalpun andreas.cadhalpun at googlemail.com
Tue Nov 8 23:36:01 EET 2016


Since the loop goes down to i = 0 the number of iterations (variable
count) is the original i, not i - 1.
In the case of i originally being 1, this miscalculation resulted in
a division by zero.

This problem was introduced in commit
4b90dcb8493552c17a811c8b1e6538dae4061f9d.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com>
---
 libavcodec/dvbsubdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index e9f4765..31898ea 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -810,7 +810,7 @@ static void compute_default_clut(AVSubtitleRect *rect, int w, int h)
         list_inv[     i ] = bestv;
     }
 
-    count = i - 1;
+    count = i;
     for (i--; i>=0; i--) {
         int v = i*255/count;
         AV_WN32(rect->data[1] + 4*list_inv[i], RGBA(v/2,v,v/2,v));
-- 
2.10.2


More information about the ffmpeg-devel mailing list