libtiff: tif_ojpeg.c fix 554 by checking for division by zero

From d0c721cad7e5e90904b0112ba56be28c35fe4394 Mon Sep 17 00:00:00 2001
From: Su Laus <[EMAIL REDACTED]>
Date: Sat, 6 May 2023 18:45:50 +0000
Subject: [PATCH] tif_ojpeg.c fix 554 by checking for division by zero

---
 libtiff/tif_ojpeg.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libtiff/tif_ojpeg.c b/libtiff/tif_ojpeg.c
index 0c915de2..ea572091 100644
--- a/libtiff/tif_ojpeg.c
+++ b/libtiff/tif_ojpeg.c
@@ -1360,6 +1360,9 @@ static int OJPEGWriteHeaderInfo(TIFF *tif)
         {
             assert(sp->subsampling_convert_ycbcrbuf == 0);
             assert(sp->subsampling_convert_ycbcrimage == 0);
+            /* Check for division by zero. */
+            if (sp->subsampling_hor == 0 || sp->subsampling_ver == 0)
+                return (0);
             sp->subsampling_convert_ylinelen =
                 ((sp->strile_width + sp->subsampling_hor * 8 - 1) /
                  (sp->subsampling_hor * 8) * sp->subsampling_hor * 8);