From 8043433ba9ce0c550e09f2b3b6a3f5f62d802e6d Mon Sep 17 00:00:00 2001
From: Cristy <urban-warrior@imagemagick.org>
Date: Tue, 15 Mar 2022 21:59:33 -0400
Subject: [PATCH] Coders:
 https://github.com/ImageMagick/ImageMagick/issues/4947

CVE: CVE-2022-1114
Upstream-Status: Backport [https://github.com/ImageMagick/ImageMagick6/commit/78f03b619d08d7c2e0fcaccab407e3ac93c2ee8f.patch]
Comments: Refreshed the patch as per codebase
Signed-off-by: Sana Kazi Sana.Kazi@kpit.com
---
 coders/dcm.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/coders/dcm.c b/coders/dcm.c
index ce6cecbd68d..879d5694d2a 100644
--- a/coders/dcm.c
+++ b/coders/dcm.c
@@ -3239,18 +3239,17 @@ static Image *ReadDCMImage(const ImageIn
           RelinquishMagickMemory(info_copy);
         }
 
-      /*
-        If we're entering a sequence, push the current image parameters onto
-        the stack, so we can restore them at the end of the sequence.
-      */
       if (strcmp(explicit_vr,"SQ") == 0)
         {
-          info_copy=(DCMInfo *) AcquireMagickMemory(sizeof(info));
-          memcpy(info_copy,&info,sizeof(info));
-          AppendValueToLinkedList(stack,info_copy);
+          /*
+            If we're entering a sequence, push the current image parameters
+            onto the stack, so we can restore them at the end of the sequence.
+          */
+          DCMInfo *clone_info = (DCMInfo *) AcquireMagickMemory(sizeof(info));
+          (void) memcpy(clone_info,&info,sizeof(info));
+          AppendValueToLinkedList(stack,clone_info);
           sequence_depth++;
         }
-
       datum=0;
       if (quantum == 4)
         {
