Blame SOURCES/0033-CVE-2022-2519-CVE-2022-2520-CVE-2022-2521-CVE-2022-2.patch

24df78
From d26748dd8fb90b0af8c9344615f65d273dc66f93 Mon Sep 17 00:00:00 2001
24df78
From: Su_Laus <sulau@freenet.de>
24df78
Date: Mon, 15 Aug 2022 22:11:03 +0200
24df78
Subject: [PATCH] =?UTF-8?q?(CVE-2022-2519=20CVE-2022-2520=20CVE-2022-2521?=
24df78
 =?UTF-8?q?=20CVE-2022-2953)=20According=20to=20Richard=20Nolde=20https://?=
24df78
 =?UTF-8?q?gitlab.com/libtiff/libtiff/-/issues/401#note=5F877637400=20the?=
24df78
 =?UTF-8?q?=20tiffcrop=20option=20=E2=80=9E-S=E2=80=9C=20is=20also=20mutua?=
24df78
 =?UTF-8?q?lly=20exclusive=20to=20the=20other=20crop=20options=20(-X|-Y),?=
24df78
 =?UTF-8?q?=20-Z=20and=20-z.?=
24df78
MIME-Version: 1.0
24df78
Content-Type: text/plain; charset=UTF-8
24df78
Content-Transfer-Encoding: 8bit
24df78
24df78
This is now checked and ends tiffcrop if those arguments are not mutually exclusive.
24df78
24df78
This MR will fix the following tiffcrop issues: #349, #414, #422, #423, #424
24df78
24df78
(cherry picked from commit 8fe3735942ea1d90d8cef843b55b3efe8ab6feaf)
24df78
---
24df78
 tools/tiffcrop.c | 31 +++++++++++++++++++++++--------
24df78
 1 file changed, 23 insertions(+), 8 deletions(-)
24df78
24df78
diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
24df78
index 5801b8f6..27e6f81c 100644
24df78
--- a/tools/tiffcrop.c
24df78
+++ b/tools/tiffcrop.c
24df78
@@ -104,7 +104,10 @@
24df78
  *                includes annotations for image parameters and scanline info. Level
24df78
  *                selects which functions dump data, with higher numbers selecting
24df78
  *                lower level, scanline level routines. Debug reports a limited set
24df78
- *                of messages to monitor progess without enabling dump logs.
24df78
+ *                of messages to monitor progress without enabling dump logs.
24df78
+ *
24df78
+ * Note:    The (-X|-Y), -Z, -z and -S options are mutually exclusive.
24df78
+ *          In no case should the options be applied to a given selection successively.
24df78
  */
24df78
 
24df78
 static   char tiffcrop_version_id[] = "2.4";
24df78
@@ -177,12 +180,12 @@ extern int getopt(int argc, char * const argv[], const char *optstring);
24df78
 #define ROTATECW_270 32
24df78
 #define ROTATE_ANY (ROTATECW_90 | ROTATECW_180 | ROTATECW_270)
24df78
 
24df78
-#define CROP_NONE     0
24df78
-#define CROP_MARGINS  1
24df78
-#define CROP_WIDTH    2
24df78
-#define CROP_LENGTH   4
24df78
-#define CROP_ZONES    8
24df78
-#define CROP_REGIONS 16
24df78
+#define CROP_NONE     0     /* "-S" -> Page_MODE_ROWSCOLS and page->rows/->cols != 0 */
24df78
+#define CROP_MARGINS  1     /* "-m" */
24df78
+#define CROP_WIDTH    2     /* "-X" */
24df78
+#define CROP_LENGTH   4     /* "-Y" */
24df78
+#define CROP_ZONES    8     /* "-Z" */
24df78
+#define CROP_REGIONS 16     /* "-z" */
24df78
 #define CROP_ROTATE  32
24df78
 #define CROP_MIRROR  64
24df78
 #define CROP_INVERT 128
24df78
@@ -320,7 +323,7 @@ struct crop_mask {
24df78
 #define PAGE_MODE_RESOLUTION   1
24df78
 #define PAGE_MODE_PAPERSIZE    2
24df78
 #define PAGE_MODE_MARGINS      4
24df78
-#define PAGE_MODE_ROWSCOLS     8
24df78
+#define PAGE_MODE_ROWSCOLS     8    /* for -S option */
24df78
 
24df78
 #define INVERT_DATA_ONLY      10
24df78
 #define INVERT_DATA_AND_TAG   11
24df78
@@ -751,6 +754,8 @@ static   char* usage_info[] = {
24df78
 "             The four debug/dump options are independent, though it makes little sense to",
24df78
 "             specify a dump file without specifying a detail level.",
24df78
 " ",
24df78
+"Note:        The (-X|-Y), -Z, -z and -S options are mutually exclusive."
24df78
+" ",
24df78
 NULL
24df78
 };
24df78
 
24df78
@@ -2099,6 +2104,16 @@ void  process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
24df78
 		/*NOTREACHED*/
24df78
       }
24df78
     }
24df78
+    /*-- Check for not allowed combinations (e.g. -X, -Y and -Z, -z and -S are mutually exclusive) --*/
24df78
+    char XY, Z, R, S;
24df78
+    XY = ((crop_data->crop_mode & CROP_WIDTH) || (crop_data->crop_mode & CROP_LENGTH));
24df78
+    Z = (crop_data->crop_mode & CROP_ZONES);
24df78
+    R = (crop_data->crop_mode & CROP_REGIONS);
24df78
+    S = (page->mode & PAGE_MODE_ROWSCOLS);
24df78
+    if ((XY && Z) || (XY && R) || (XY && S) || (Z && R) || (Z && S) || (R && S)) {
24df78
+        TIFFError("tiffcrop input error", "The crop options(-X|-Y), -Z, -z and -S are mutually exclusive.->Exit");
24df78
+        exit(EXIT_FAILURE);
24df78
+    }
24df78
   }  /* end process_command_opts */
24df78
 
24df78
 /* Start a new output file if one has not been previously opened or