[med-svn] [Git][med-team/dcmtk][debian/experimental] 28 commits: Prevent bashism in run-unit-test
Mathieu Malaterre (@malat)
gitlab at salsa.debian.org
Mon Jun 24 19:47:14 BST 2024
Mathieu Malaterre pushed to branch debian/experimental at Debian Med / dcmtk
Commits:
1de8f04a by Andreas Tille at 2022-09-28T15:08:06+02:00
Prevent bashism in run-unit-test
- - - - -
5eae20a2 by Andreas Tille at 2022-09-28T15:09:24+02:00
Enable running run-unit-test from any directory
- - - - -
3c698020 by Mathieu Malaterre at 2022-11-07T11:24:02+01:00
d/control: Add missing dependency on libjs-jquery. Closes: #989108
- - - - -
e3b0ad4c by Andreas Tille at 2022-12-06T11:49:27+01:00
Add maintscript to remove outdated conffiles
- - - - -
90045e1a by Andreas Tille at 2022-12-06T11:52:34+01:00
On purge remove /var/lib/dcmtk/db/STORESCP if exists
- - - - -
e6fdde0b by Andreas Tille at 2022-12-06T12:14:30+01:00
Upload to unstable
- - - - -
5246f1f1 by Mathieu Malaterre at 2023-01-04T11:14:53+01:00
d/patches: Fix CVE-2022-43272. Closes: #1027165
- - - - -
3ad07841 by Mathieu Malaterre at 2023-01-04T11:14:53+01:00
d/control: Bump Std-Vers to 4.6.2 no changes needed
- - - - -
813aa719 by Mathieu Malaterre at 2023-01-04T11:15:22+01:00
d/changelog: Upload 3.6.7-8 to unstable
- - - - -
b3a5215a by Andreas Tille at 2023-06-22T09:52:33+02:00
Fix postrm
- - - - -
4190250e by Andreas Tille at 2023-06-22T11:01:22+02:00
Upload to unstable
- - - - -
d24b828b by Michael Hudson-Doyle at 2024-02-28T12:20:16+01:00
Rename libraries for 64-bit time_t transition.
Closes: #1062022
Signed-off-by: Étienne Mollier <emollier at debian.org>
- - - - -
43b3d025 by jodogne-guest at 2024-03-19T11:08:09+01:00
d/rules: Fix armel buildd
- - - - -
b9ec3095 by jodogne-guest at 2024-03-19T11:26:36+01:00
Upload to unstable
- - - - -
be32cee3 by jodogne-guest at 2024-03-19T11:55:03+01:00
Fix typo in target distribution during upload
- - - - -
8056d726 by jodogne-guest at 2024-03-19T12:01:05+01:00
Upload to unstable
- - - - -
fc6df8ea by Emanuele Rocca at 2024-03-19T12:32:26+01:00
Do not build-depend on graphviz on armhf and armel.
The package is currently not installable on those arches due to the ongoing t64
transition.
Co-authored-by: Michael R. Crusoe <crusoe at debian.org>
- - - - -
a9e3512b by Michael R. Crusoe at 2024-03-19T12:39:12+01:00
Acknowledge NMU
- - - - -
1dea414a by Michael R. Crusoe at 2024-03-19T12:43:51+01:00
Marked Debian-specific patches as not needing forwarding to upstream.
- - - - -
7378bd08 by Michael R. Crusoe at 2024-03-19T15:23:29+01:00
d/control: add explicit dependency on libnsl-dev. Closes: #1066422.
- - - - -
be4d90b6 by Michael R. Crusoe at 2024-03-19T15:24:15+01:00
routine-update: Ready to upload to unstable
- - - - -
da72b727 by Emanuele Rocca at 2024-03-22T11:13:49+01:00
[armhf,armel] No need to drop graphviz from build-depends-indep
Build-Depends-Indep are only used to build the arch:all packages, and currently
all the arch:all autobuilder run on amd64.
- - - - -
6ec0127d by Santiago Vila at 2024-06-05T14:33:17+02:00
Apply patches from NMU proposal by Adrian Bunk to address CVE-2024-28130, CVE-2024-34508 and CVE-2024-34509. Closes: #1070207.
- - - - -
e5c8d3e2 by Santiago Vila at 2024-06-05T14:34:12+02:00
Upload for unstable as 3.6.7-14
- - - - -
965a8033 by Santiago Vila at 2024-06-24T12:31:14+02:00
Update two of the previously applied patches to avoid breaking the ABI. Closes: #1070207.
The updated patches are:
0001-Fixed-unchecked-typecasts-of-DcmItem-search-results.patch
0003-Fixed-wrong-error-handling-previous-commit.patch
- - - - -
d4ea4513 by Santiago Vila at 2024-06-24T12:33:56+02:00
Upload for unstable as 3.6.7-15
- - - - -
ed74b85b by Mathieu Malaterre at 2024-06-24T20:43:42+02:00
Merge branch 'master' into debian/experimental
- - - - -
207c46c2 by Mathieu Malaterre at 2024-06-24T20:44:16+02:00
d/changelog: Upload 3.6.8-4 to experimental
- - - - -
16 changed files:
- debian/changelog
- debian/control
- + debian/dcmtk.maintscript
- debian/dcmtk.postrm
- + debian/patches/0001-Fixed-unchecked-typecasts-of-DcmItem-search-results.patch
- + debian/patches/0002-Fixed-unchecked-typecasts-and-fixed-LUT-handling.patch
- + debian/patches/0003-Fixed-wrong-error-handling-previous-commit.patch
- + debian/patches/0004-Fixed-two-segmentation-faults.patch
- + debian/patches/0005-Fixed-DcmDecimalString-unit-tests.patch
- debian/patches/01_dcmtk_3.6.0-1.patch
- debian/patches/03_datadic_install.patch
- debian/patches/07_dont_export_all_executables.patch
- − debian/patches/fake_version.patch
- debian/patches/series
- debian/rules
- debian/tests/run-unit-test
Changes:
=====================================
debian/changelog
=====================================
@@ -1,82 +1,103 @@
-dcmtk (3.6.8-3) experimental; urgency=medium
+dcmtk (3.6.8-4) experimental; urgency=medium
- [ Emanuele Rocca ]
- * d/rules: Fix armel buildd
+ * d/rules: Add dcmtk-data package
+ * d/control: Add missing dependency on libjs-jquery. Closes: #989108
+ * d/control: Reduce number of dependencies for -dev package
+ * New upstream version 3.6.8
- -- Mathieu Malaterre <malat at debian.org> Fri, 12 Jan 2024 17:09:17 +0100
+ -- Mathieu Malaterre <malat at debian.org> Mon, 24 Jun 2024 20:43:54 +0200
-dcmtk (3.6.8-2) experimental; urgency=medium
+dcmtk (3.6.7-15) unstable; urgency=medium
- * d/rules: Fix test suite on x87 hardware
- * d/patches: Import bug fix from upstream
+ * Team upload.
+ [ Adrian Bunk ]
+ * Update two of the previously applied patches to avoid breaking the ABI.
+ Closes: #1070207.
- -- Mathieu Malaterre <malat at debian.org> Fri, 12 Jan 2024 10:34:32 +0100
+ -- Santiago Vila <sanvila at debian.org> Mon, 24 Jun 2024 12:30:00 +0200
-dcmtk (3.6.8-1) experimental; urgency=medium
+dcmtk (3.6.7-14) unstable; urgency=medium
- * New upstream version 3.6.8
- * d/patches: Refresh patches
+ * Team upload.
+ [ Emanuele Rocca ]
+ * Do not drop graphviz from build-depends-indep for armhf and armel.
+ [ Adrian Bunk ]
+ * CVE-2024-28130: Segmentation faults due to incorrect typecast
+ (Closes: #1070207)
+ * CVE-2024-34508: Segmentation fault via invalid DIMSE message
+ * CVE-2024-34509: Segmentation fault via invalid DIMSE message
- -- Mathieu Malaterre <malat at debian.org> Thu, 11 Jan 2024 15:42:25 +0100
+ -- Santiago Vila <sanvila at debian.org> Wed, 05 Jun 2024 14:30:00 +0200
-dcmtk (3.6.8~git20231027.1549d8c-2) experimental; urgency=medium
+dcmtk (3.6.7-13) unstable; urgency=medium
- * d/patches: Fix install path for docs
+ * Team upload.
+ * Marked Debian-specific patches as not needing forwarding to
+ upstream.
+ * d/control: add explicit dependency on libnsl-dev. Closes: #1066422.
- -- Mathieu Malaterre <malat at debian.org> Mon, 06 Nov 2023 12:07:47 +0100
+ -- Michael R. Crusoe <crusoe at debian.org> Tue, 19 Mar 2024 15:24:15 +0100
-dcmtk (3.6.8~git20231027.1549d8c-1) experimental; urgency=medium
+dcmtk (3.6.7-12) unstable; urgency=medium
- * New upstream version 3.6.8~git20231027.1549d8c
- * d/patches: Remove version from install paths
- * d/rules: Start using LTO
+ * Team upload.
- -- Mathieu Malaterre <malat at debian.org> Mon, 06 Nov 2023 10:27:49 +0100
+ [ Emanuele Rocca ]
+ * Do not build-depend on graphviz on armhf and armel. The package is
+ currently not installable on those arches due to the ongoing t64
+ transition. Closes: #1067147
-dcmtk (3.6.8~git20221024.b8950f9-3) experimental; urgency=medium
+ -- Michael R. Crusoe <crusoe at debian.org> Tue, 19 Mar 2024 12:30:03 +0100
- * d/patches: Remove obsolete/unused patches
- * d/rules: Fix debuild -A (all)
+dcmtk (3.6.7-11) unstable; urgency=medium
- -- Mathieu Malaterre <malat at debian.org> Fri, 30 Jun 2023 15:27:28 +0200
+ * Fix typo in target distribution during upload.
-dcmtk (3.6.8~git20221024.b8950f9-2) experimental; urgency=medium
+ -- Sebastien Jodogne <s.jodogne at gmail.com> Tue, 19 Mar 2024 11:54:38 +0100
- * d/control: Reduce number of dependencies for -dev package
- * d/rules: Remove gnu extensions, only strict c++17
- * d/rules: Do not build test suite if not required
+dcmtk (3.6.7-10) unreleased; urgency=medium
+
+ * Fix build on armel. Closes: #1060104
- -- Mathieu Malaterre <malat at debian.org> Fri, 30 Jun 2023 14:19:10 +0200
+ -- Sebastien Jodogne <s.jodogne at gmail.com> Tue, 19 Mar 2024 11:03:28 +0100
-dcmtk (3.6.8~git20221024.b8950f9-1) experimental; urgency=medium
+dcmtk (3.6.7-9.1) unstable; urgency=medium
- * New upstream version 3.6.8~git20221024.b8950f9
- * d/patches: Refresh version for new snapshot
+ * Non-maintainer upload.
+ * Rename libraries for 64-bit time_t transition. Closes: #1062022
- -- Mathieu Malaterre <malat at debian.org> Mon, 07 Nov 2022 16:39:05 +0100
+ -- Michael Hudson-Doyle <mwhudson at debian.org> Wed, 28 Feb 2024 01:17:02 +0000
-dcmtk (3.6.8~git20221013.51be018-3) experimental; urgency=medium
+dcmtk (3.6.7-9) unstable; urgency=medium
- * d/doc-base: Fix full path
+ * Team upload.
+ * Fix postrm
+ Closes: #1038776
- -- Mathieu Malaterre <malat at debian.org> Mon, 07 Nov 2022 13:33:45 +0100
+ -- Andreas Tille <tille at debian.org> Thu, 22 Jun 2023 09:53:48 +0200
-dcmtk (3.6.8~git20221013.51be018-2) experimental; urgency=medium
+dcmtk (3.6.7-8) unstable; urgency=medium
- * d/lintian: Make sure to override lintian/ijg check
- * d/control: Add missing dependency on libjs-jquery. Closes: #989108
+ * d/patches: Fix CVE-2022-43272. Closes: #1027165
+ * d/control: Bump Std-Vers to 4.6.2 no changes needed
- -- Mathieu Malaterre <malat at debian.org> Mon, 07 Nov 2022 11:28:31 +0100
+ -- Mathieu Malaterre <malat at debian.org> Wed, 04 Jan 2023 11:15:13 +0100
-dcmtk (3.6.8~git20221013.51be018-1) experimental; urgency=medium
+dcmtk (3.6.7-7) unstable; urgency=medium
- * d/watch: Point to git HEAD
- * New upstream version 3.6.8~git20221013.51be018
- * d/rules: Add dcmtk-data package
- * d/install: Start migrating to new 18 ABI
- * d/patches: Add fake version mechanism
+ [ Andreas Tille ]
+ * Team upload.
+ * Prevent bashism in run-unit-test
+ * Enable running run-unit-test from any directory
+ * Add maintscript to remove outdated conffiles
+ Closes: #990134
+ * On purge remove /var/lib/dcmtk/db/STORESCP if exists
+ Closes: #990135
+
+ [ Mathieu Malaterre ]
+ * d/control: Add missing dependency on libjs-jquery. Closes: #989108
- -- Mathieu Malaterre <malat at debian.org> Mon, 07 Nov 2022 10:53:17 +0100
+ -- Andreas Tille <tille at debian.org> Tue, 06 Dec 2022 11:52:52 +0100
dcmtk (3.6.7-6) unstable; urgency=medium
=====================================
debian/control
=====================================
@@ -5,8 +5,10 @@ Section: science
Priority: optional
Build-Depends: cmake,
debhelper-compat (= 13),
+ dpkg-dev (>= 1.22.5),
gettext,
help2man,
+ libnsl-dev,
libpng-dev,
libsndfile1-dev,
libssl-dev,
@@ -16,7 +18,7 @@ Build-Depends: cmake,
xxd,
zlib1g-dev
Build-Depends-Indep: doxygen, graphviz
-Standards-Version: 4.6.1
+Standards-Version: 4.6.2
Vcs-Browser: https://salsa.debian.org/med-team/dcmtk
Vcs-Git: https://salsa.debian.org/med-team/dcmtk.git
Homepage: https://dicom.offis.de/dcmtk
@@ -69,6 +71,8 @@ Package: libdcmtk-dev
Architecture: any
Section: libdevel
Depends: libdcmtk18 (= ${binary:Version}),
+ libnsl-dev,
+ libwrap0-dev,
libxml2-dev,
libz-dev,
${misc:Depends}
=====================================
debian/dcmtk.maintscript
=====================================
@@ -0,0 +1,4 @@
+rm_conffile /etc/default/dcmqrscp
+rm_conffile /etc/default/storescp
+rm_conffile /etc/init.d/dcmqrscp
+rm_conffile /etc/init.d/storescp
=====================================
debian/dcmtk.postrm
=====================================
@@ -13,6 +13,10 @@ if [ "$1" = "purge" ] ; then
if [ -e /etc/init.d/imagectn.dpkg-old ]; then
rm -f /etc/init.d/imagectn.dpkg-old
fi
+
+ if [ -d /var/lib/dcmtk/db/STORESCP ]; then
+ rm -rf /var/lib/dcmtk/db/STORESCP
+ fi
fi
# Remove dcmtk user/group if they exist on cleanup
=====================================
debian/patches/0001-Fixed-unchecked-typecasts-of-DcmItem-search-results.patch
=====================================
@@ -0,0 +1,1662 @@
+From dc6a2446dc03c9db90f82ce17a597f2cd53776c5 Mon Sep 17 00:00:00 2001
+From: Marco Eichelberg <dicom at offis.de>
+Date: Mon, 15 Apr 2024 12:12:51 +0200
+Subject: [PATCH] Fixed unchecked typecasts of DcmItem::search results.
+
+DcmItem::search() returns a stack of DcmObject pointers as search results.
+These pointers in most instances need to be casted to DcmItem, DcmElement
+or a subclass of these. In many cases, the type of the object was not
+properly checked before the typecast. This could lead to segmentation faults
+when invalid DICOM datasets were processed where elements had the wrong
+value representation.
+---
+ dcmdata/apps/cda2dcm.cc | 0
+ dcmdata/apps/stl2dcm.cc | 0
+ dcmdata/include/dcmtk/dcmdata/dcelem.h | 7 +++-
+ dcmdata/include/dcmtk/dcmdata/dcencdoc.h | 0
+ dcmdata/include/dcmtk/dcmdata/dcobject.h | 7 +++-
+ dcmdata/libsrc/dcddirif.cc | 4 +--
+ dcmdata/libsrc/dcdirrec.cc | 6 ++--
+ dcmdata/libsrc/dcfilefo.cc | 12 +++----
+ dcmdata/libsrc/dcitem.cc | 16 ++++-----
+ dcmimgle/libsrc/didocu.cc | 2 +-
+ dcmiod/libsrc/iodutil.cc | 4 +--
+ dcmjpeg/libsrc/djcodece.cc | 8 ++---
+ dcmnet/apps/storescu.cc | 8 ++++-
+ dcmnet/libsrc/dimcmd.cc | 38 ++++++++++++---------
+ dcmnet/libsrc/diutil.cc | 28 ++++++++--------
+ dcmnet/libsrc/dstorscu.cc | 2 +-
+ dcmpstat/apps/dcmmklut.cc | 6 ++--
+ dcmpstat/apps/dcmpschk.cc | 8 +++--
+ dcmpstat/libsrc/dviface.cc | 10 +++---
+ dcmpstat/libsrc/dvpsabl.cc | 4 +--
+ dcmpstat/libsrc/dvpscu.cc | 18 +++++-----
+ dcmpstat/libsrc/dvpsdal.cc | 4 +--
+ dcmpstat/libsrc/dvpsfs.cc | 22 ++++++-------
+ dcmpstat/libsrc/dvpsgal.cc | 4 +--
+ dcmpstat/libsrc/dvpsgll.cc | 4 +--
+ dcmpstat/libsrc/dvpsgrl.cc | 4 +--
+ dcmpstat/libsrc/dvpshlp.cc | 2 +-
+ dcmpstat/libsrc/dvpsib.cc | 42 ++++++++++++------------
+ dcmpstat/libsrc/dvpsibl.cc | 4 +--
+ dcmpstat/libsrc/dvpspll.cc | 4 +--
+ dcmpstat/libsrc/dvpsril.cc | 4 +--
+ dcmpstat/libsrc/dvpsrsl.cc | 4 +--
+ dcmpstat/libsrc/dvpssp.cc | 40 +++++++++++-----------
+ dcmpstat/libsrc/dvpstxl.cc | 4 +--
+ dcmpstat/libsrc/dvpsvll.cc | 4 +--
+ dcmrt/libsrc/drttypes.cc | 8 ++---
+ dcmsign/libsrc/dcsignat.cc | 22 ++++++-------
+ dcmsign/libsrc/sicert.cc | 4 +--
+ dcmsr/libsrc/dsrtypes.cc | 6 ++--
+ 39 files changed, 199 insertions(+), 175 deletions(-)
+ mode change 100755 => 100644 dcmdata/apps/cda2dcm.cc
+ mode change 100755 => 100644 dcmdata/apps/stl2dcm.cc
+ mode change 100755 => 100644 dcmdata/include/dcmtk/dcmdata/dcencdoc.h
+
+diff --git a/dcmdata/apps/cda2dcm.cc b/dcmdata/apps/cda2dcm.cc
+old mode 100755
+new mode 100644
+diff --git a/dcmdata/apps/stl2dcm.cc b/dcmdata/apps/stl2dcm.cc
+old mode 100755
+new mode 100644
+diff --git a/dcmdata/include/dcmtk/dcmdata/dcelem.h b/dcmdata/include/dcmtk/dcmdata/dcelem.h
+index b6ffeb7eb0..2978e96180 100644
+--- a/dcmdata/include/dcmtk/dcmdata/dcelem.h
++++ b/dcmdata/include/dcmtk/dcmdata/dcelem.h
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1994-2023, OFFIS e.V.
++ * Copyright (C) 1994-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -144,6 +144,11 @@ class DCMTK_DCMDATA_EXPORT DcmElement
+ */
+ virtual OFBool isLeaf() const { return OFTrue; }
+
++ /** check if this element can be safely casted to DcmElement
++ * @return true if DcmElement, false otherwise
++ */
++ virtual OFBool isElement() const { return OFTrue; }
++
+ /** check if value of this element is loaded into main memory
+ * @return true if value is present in memory, false if value still resides in file
+ */
+diff --git a/dcmdata/include/dcmtk/dcmdata/dcencdoc.h b/dcmdata/include/dcmtk/dcmdata/dcencdoc.h
+old mode 100755
+new mode 100644
+diff --git a/dcmdata/include/dcmtk/dcmdata/dcobject.h b/dcmdata/include/dcmtk/dcmdata/dcobject.h
+index 60490f6bc8..714520bcf5 100644
+--- a/dcmdata/include/dcmtk/dcmdata/dcobject.h
++++ b/dcmdata/include/dcmtk/dcmdata/dcobject.h
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1994-2020, OFFIS e.V.
++ * Copyright (C) 1994-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -308,6 +308,11 @@ class DCMTK_DCMDATA_EXPORT DcmObject
+ */
+ virtual OFBool isLeaf() const = 0;
+
++ /** check if this element can be safely casted to DcmElement
++ * @return true if DcmElement, false otherwise
++ */
++ virtual OFBool isElement() const { return OFFalse; }
++
+ /** check if this element is nested in a sequence of items, i.e.\ not a
+ * top-level or stand-alone element
+ * @return true if this element is nested, false otherwise
+diff --git a/dcmdata/libsrc/dcddirif.cc b/dcmdata/libsrc/dcddirif.cc
+index a0aec59b96..69d0993e5f 100644
+--- a/dcmdata/libsrc/dcddirif.cc
++++ b/dcmdata/libsrc/dcddirif.cc
+@@ -433,7 +433,7 @@ static OFBool compareItems(DcmItem *item1,
+ OFBool first = OFTrue;
+ DcmStack stack1, stack2;
+ /* check whether attributes are equal */
+- while (item1->nextObject(stack1, first).good() && item2->nextObject(stack2, first).good())
++ while (item1->nextObject(stack1, first).good() && item2->nextObject(stack2, first).good() && stack1.top()->isElement() && stack2.top()->isElement())
+ {
+ if (!compareAttributes(OFstatic_cast(DcmElement *, stack1.top()), OFstatic_cast(DcmElement *, stack2.top()), fromSequence, i++, reason))
+ break;
+@@ -5457,7 +5457,7 @@ OFBool DicomDirInterface::warnAboutInconsistentAttributes(DcmDirectoryRecord *re
+ OFBool first = OFTrue;
+ DcmElement *delem = NULL;
+ /* iterate over all record elements */
+- while (record->nextObject(stack, first).good() && (result || !abortCheck))
++ while (record->nextObject(stack, first).good() && (result || !abortCheck) && stack.top()->isElement())
+ {
+ delem = OFstatic_cast(DcmElement *, stack.top());
+ if ((delem != NULL) && (delem->getLength() > 0))
+diff --git a/dcmdata/libsrc/dcdirrec.cc b/dcmdata/libsrc/dcdirrec.cc
+index a6a2fc4858..c374c34742 100644
+--- a/dcmdata/libsrc/dcdirrec.cc
++++ b/dcmdata/libsrc/dcdirrec.cc
+@@ -998,7 +998,7 @@ OFCondition DcmDirectoryRecord::fillElementsAndReadSOP(const char *referencedFil
+ DCMDATA_ERROR("Internal ERROR in DcmDirectoryRecord::fillElementsAndReadSOP()");
+ }
+ uiP = new DcmUniqueIdentifier(refSOPClassTag); // (0004,1510)
+- if (refFile->search(DCM_SOPClassUID, stack).good())
++ if (refFile->search(DCM_SOPClassUID, stack).good() && (stack.top()->ident() == EVR_UI))
+ {
+ char *uid = NULL;
+ OFstatic_cast(DcmUniqueIdentifier *, stack.top())->getString(uid);
+@@ -1011,7 +1011,7 @@ OFCondition DcmDirectoryRecord::fillElementsAndReadSOP(const char *referencedFil
+ insert(uiP, OFTrue);
+
+ uiP = new DcmUniqueIdentifier(refSOPInstTag); // (0004,1511)
+- if (refFile->search(DCM_SOPInstanceUID, stack).good() || refFile->search(DCM_MediaStorageSOPInstanceUID, stack).good())
++ if ((refFile->search(DCM_SOPInstanceUID, stack).good() || refFile->search(DCM_MediaStorageSOPInstanceUID, stack).good()) && (stack.top()->ident() == EVR_UI))
+ {
+ char *uid = NULL;
+ OFstatic_cast(DcmUniqueIdentifier *, stack.top())->getString(uid);
+@@ -1024,7 +1024,7 @@ OFCondition DcmDirectoryRecord::fillElementsAndReadSOP(const char *referencedFil
+ insert(uiP, OFTrue);
+
+ uiP = new DcmUniqueIdentifier(refFileXferTag); // (0004,1512)
+- if (refFile->search(DCM_TransferSyntaxUID, stack).good())
++ if (refFile->search(DCM_TransferSyntaxUID, stack).good() && (stack.top()->ident() == EVR_UI))
+ {
+ char *uid = NULL;
+ OFstatic_cast(DcmUniqueIdentifier *, stack.top())->getString(uid);
+diff --git a/dcmdata/libsrc/dcfilefo.cc b/dcmdata/libsrc/dcfilefo.cc
+index 4f72dee83d..5771e604cc 100644
+--- a/dcmdata/libsrc/dcfilefo.cc
++++ b/dcmdata/libsrc/dcfilefo.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1994-2022, OFFIS e.V.
++ * Copyright (C) 1994-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -362,7 +362,7 @@ OFCondition DcmFileFormat::checkMetaHeaderValue(DcmMetaInfo *metainfo,
+ {
+ if ((writeMode == EWM_updateMeta) || (elem->getLength() == 0))
+ {
+- if (dataset->search(DCM_SOPClassUID, stack).good())
++ if (dataset->search(DCM_SOPClassUID, stack).good() && (stack.top()->ident() == EVR_UI))
+ {
+ char *uid = NULL;
+ l_error = OFstatic_cast(DcmUniqueIdentifier *, stack.top())->getString(uid);
+@@ -378,7 +378,7 @@ OFCondition DcmFileFormat::checkMetaHeaderValue(DcmMetaInfo *metainfo,
+ else if (DCM_dcmdataLogger.isEnabledFor(OFLogger::WARN_LOG_LEVEL))
+ {
+ // check whether UID in meta-header is identical to the one in the dataset
+- if (dataset->search(DCM_SOPClassUID, stack).good())
++ if (dataset->search(DCM_SOPClassUID, stack).good() && (stack.top()->ident() == EVR_UI))
+ {
+ OFString uidDataset, uidMetaHeader;
+ OFstatic_cast(DcmUniqueIdentifier *, stack.top())->getOFStringArray(uidDataset);
+@@ -404,7 +404,7 @@ OFCondition DcmFileFormat::checkMetaHeaderValue(DcmMetaInfo *metainfo,
+ {
+ if ((writeMode == EWM_updateMeta) || (elem->getLength() == 0))
+ {
+- if (dataset->search(DCM_SOPInstanceUID, stack).good())
++ if (dataset->search(DCM_SOPInstanceUID, stack).good() && (stack.top()->ident() == EVR_UI))
+ {
+ char* uid = NULL;
+ l_error = OFstatic_cast(DcmUniqueIdentifier *, stack.top())->getString(uid);
+@@ -422,7 +422,7 @@ OFCondition DcmFileFormat::checkMetaHeaderValue(DcmMetaInfo *metainfo,
+ else if (DCM_dcmdataLogger.isEnabledFor(OFLogger::WARN_LOG_LEVEL))
+ {
+ // check whether UID in meta-header is identical to the one in the dataset
+- if (dataset->search(DCM_SOPInstanceUID, stack).good())
++ if (dataset->search(DCM_SOPInstanceUID, stack).good() && (stack.top()->ident() == EVR_UI))
+ {
+ OFString uidDataset, uidMetaHeader;
+ OFstatic_cast(DcmUniqueIdentifier *, stack.top())->getOFStringArray(uidDataset);
+@@ -633,7 +633,7 @@ E_TransferSyntax DcmFileFormat::lookForXfer(DcmMetaInfo *metainfo)
+ /* check whether meta header is present (and non-empty, i.e. contains elements) */
+ if (metainfo && !metainfo->isEmpty())
+ {
+- if (metainfo->search(DCM_TransferSyntaxUID, stack).good())
++ if (metainfo->search(DCM_TransferSyntaxUID, stack).good() && (stack.top()->ident() == EVR_UI))
+ {
+ DcmUniqueIdentifier *xferUI = OFstatic_cast(DcmUniqueIdentifier *, stack.top());
+ if (xferUI->getTag() == DCM_TransferSyntaxUID)
+diff --git a/dcmdata/libsrc/dcitem.cc b/dcmdata/libsrc/dcitem.cc
+index 3960fceb45..51f95d21dd 100644
+--- a/dcmdata/libsrc/dcitem.cc
++++ b/dcmdata/libsrc/dcitem.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1994-2023, OFFIS e.V.
++ * Copyright (C) 1994-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -2332,7 +2332,7 @@ OFBool DcmItem::tagExistsWithValue(const DcmTagKey &key,
+ DcmStack stack;
+ OFBool result = OFFalse;
+
+- if (search(key, stack, ESM_fromHere, searchIntoSub).good())
++ if (search(key, stack, ESM_fromHere, searchIntoSub).good() && stack.top()->isElement())
+ {
+ DcmElement *elem = OFstatic_cast(DcmElement *, stack.top());
+ if (elem != NULL)
+@@ -2355,7 +2355,7 @@ OFCondition DcmItem::findAndGetElement(const DcmTagKey &tagKey,
+ DcmStack stack;
+ /* find the element */
+ OFCondition status = search(tagKey, stack, ESM_fromHere, searchIntoSub);
+- if (status.good())
++ if (status.good() && stack.top()->isElement())
+ {
+ element = OFstatic_cast(DcmElement *, stack.top());
+ /* should never happen but ... */
+@@ -2990,7 +2990,7 @@ OFCondition DcmItem::findAndGetSequence(const DcmTagKey &seqTagKey,
+ DcmStack stack;
+ /* find the element */
+ OFCondition status = search(seqTagKey, stack, ESM_fromHere, searchIntoSub);
+- if (status.good())
++ if (status.good() && stack.top()->isElement())
+ {
+ DcmElement *delem = OFstatic_cast(DcmElement *, stack.top());
+ /* should never happen but ... */
+@@ -3027,7 +3027,7 @@ OFCondition DcmItem::findAndGetSequenceItem(const DcmTagKey &seqTagKey,
+ DcmStack stack;
+ /* find sequence */
+ OFCondition status = search(seqTagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+- if (status.good())
++ if (status.good() && stack.top()->isElement())
+ {
+ /* get element */
+ DcmElement *delem = OFstatic_cast(DcmElement *, stack.top());
+@@ -3089,7 +3089,7 @@ OFCondition DcmItem::findOrCreateSequenceItem(const DcmTag& seqTag,
+ OFCondition status = search(seqTag, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+ DcmSequenceOfItems *sequence = NULL;
+ /* sequence found? */
+- if (status.good())
++ if (status.good() && stack.top()->isElement())
+ {
+ /* get element */
+ DcmElement *delem = OFstatic_cast(DcmElement *, stack.top());
+@@ -3223,7 +3223,7 @@ OFCondition DcmItem::findAndDeleteSequenceItem(const DcmTagKey &seqTagKey,
+ DcmStack stack;
+ /* find sequence */
+ OFCondition status = search(seqTagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+- if (status.good())
++ if (status.good() && stack.top()->isElement())
+ {
+ /* get element */
+ DcmElement *delem = OFstatic_cast(DcmElement *, stack.top());
+@@ -4224,7 +4224,7 @@ OFCondition DcmItem::insertSequenceItem(const DcmTag &seqTag,
+ status = search(seqTag, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+ DcmSequenceOfItems *sequence = NULL;
+ /* sequence found? */
+- if (status.good())
++ if (status.good() && stack.top()->isElement())
+ {
+ /* get element */
+ DcmElement *delem = OFstatic_cast(DcmElement *, stack.top());
+diff --git a/dcmimgle/libsrc/didocu.cc b/dcmimgle/libsrc/didocu.cc
+index b63f77258a..efbbd69fbd 100644
+--- a/dcmimgle/libsrc/didocu.cc
++++ b/dcmimgle/libsrc/didocu.cc
+@@ -217,7 +217,7 @@ DcmElement *DiDocument::search(const DcmTagKey &tag,
+ obj = Object;
+ // only search on main dataset level
+ if ((obj != NULL) && (obj->search(tag, stack, ESM_fromHere, OFFalse /* searchIntoSub */) == EC_Normal) &&
+- (stack.top()->getLength(Xfer) > 0))
++ (stack.top()->getLength(Xfer) > 0) && stack.top()->isElement())
+ {
+ return OFstatic_cast(DcmElement *, stack.top());
+ }
+diff --git a/dcmiod/libsrc/iodutil.cc b/dcmiod/libsrc/iodutil.cc
+index bd3dc87913..64c985cb50 100644
+--- a/dcmiod/libsrc/iodutil.cc
++++ b/dcmiod/libsrc/iodutil.cc
+@@ -43,7 +43,7 @@ OFCondition DcmIODUtil::getAndCheckElementFromDataset(
+ DcmStack stack;
+ const DcmTagKey tagKey = delem.getTag();
+ OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+- if (result.good())
++ if (result.good() && stack.top()->isElement())
+ {
+ /* copy object from search stack */
+ result = delem.copyFrom(*stack.top());
+@@ -76,7 +76,7 @@ OFCondition DcmIODUtil::getAndCheckElementFromDataset(DcmItem& dataset,
+
+ DcmStack stack;
+ OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+- if (result.good())
++ if (result.good() && stack.top()->isElement())
+ {
+ /* copy object from search stack */
+ delem = OFstatic_cast(DcmElement*, stack.top()->clone());
+diff --git a/dcmjpeg/libsrc/djcodece.cc b/dcmjpeg/libsrc/djcodece.cc
+index 4128a20402..d0371f6c2b 100644
+--- a/dcmjpeg/libsrc/djcodece.cc
++++ b/dcmjpeg/libsrc/djcodece.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 2001-2022, OFFIS e.V.
++ * Copyright (C) 2001-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -1399,17 +1399,17 @@ OFCondition DJCodecEncoder::correctVOIWindows(
+ DcmElement *explanation = NULL;
+
+ DcmStack stack;
+- if ((dataset->search(DCM_WindowCenter, stack, ESM_fromHere, OFFalse)).good())
++ if ((dataset->search(DCM_WindowCenter, stack, ESM_fromHere, OFFalse)).good() && stack.top()->isElement())
+ {
+ center = OFreinterpret_cast(DcmElement*, stack.top());
+ }
+ stack.clear();
+- if ((dataset->search(DCM_WindowWidth, stack, ESM_fromHere, OFFalse)).good())
++ if ((dataset->search(DCM_WindowWidth, stack, ESM_fromHere, OFFalse)).good() && stack.top()->isElement())
+ {
+ width = OFreinterpret_cast(DcmElement*, stack.top());
+ }
+ stack.clear();
+- if ((dataset->search(DCM_WindowCenterWidthExplanation, stack, ESM_fromHere, OFFalse)).good())
++ if ((dataset->search(DCM_WindowCenterWidthExplanation, stack, ESM_fromHere, OFFalse)).good() && stack.top()->isElement())
+ {
+ explanation = OFreinterpret_cast(DcmElement*, stack.top());
+ }
+diff --git a/dcmnet/apps/storescu.cc b/dcmnet/apps/storescu.cc
+index e2c3b29395..bd7f1cd61f 100644
+--- a/dcmnet/apps/storescu.cc
++++ b/dcmnet/apps/storescu.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1996-2023, OFFIS e.V.
++ * Copyright (C) 1996-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -1138,6 +1138,12 @@ updateStringAttributeValue(DcmItem *dataset, const DcmTagKey &key, OFString &val
+ return OFFalse;
+ }
+
++ if (! stack.top()->isElement())
++ {
++ OFLOG_ERROR(storescuLogger, "updateStringAttributeValue: not a DcmElement: " << tag.getTagName() << " " << key);
++ return OFFalse;
++ }
++
+ DcmElement *elem = OFstatic_cast(DcmElement *, stack.top());
+
+ DcmVR vr(elem->ident());
+diff --git a/dcmnet/libsrc/dimcmd.cc b/dcmnet/libsrc/dimcmd.cc
+index ffd225f4b9..3bcfae5e4f 100644
+--- a/dcmnet/libsrc/dimcmd.cc
++++ b/dcmnet/libsrc/dimcmd.cc
+@@ -191,14 +191,16 @@ addString(DcmDataset *obj, DcmTagKey t, char *s, OFBool keepPadding)
+ static OFCondition
+ getString(DcmDataset *obj, DcmTagKey t, char *s, int maxlen, OFBool *spacePadded)
+ {
+- DcmElement *elem;
++ DcmElement *elem = NULL;
+ DcmStack stack;
+ OFCondition ec = EC_Normal;
+ char* aString;
+
+ ec = obj->search(t, stack);
+- elem = (DcmElement*)stack.top();
+- if (ec == EC_Normal && elem != NULL) {
++ if (ec.good() && stack.top()->isElement())
++ elem = (DcmElement*)stack.top();
++
++ if (elem != NULL) {
+ if (elem->getLength() == 0) {
+ s[0] = '\0';
+ } else if (elem->getLength() > (Uint32)maxlen) {
+@@ -266,17 +268,19 @@ addUS(DcmDataset *obj, DcmTagKey t, Uint16 us)
+ static OFCondition
+ getUS(DcmDataset *obj, DcmTagKey t, Uint16 *us)
+ {
+- DcmElement *elem;
++ DcmElement *elem = NULL;
+ DcmStack stack;
+ OFCondition ec = EC_Normal;
+
+ ec = obj->search(t, stack);
+- elem = (DcmElement*)stack.top();
+- if (ec == EC_Normal && elem != NULL) {
++ if (ec.good() && stack.top()->isElement())
++ elem = (DcmElement*)stack.top();
++
++ if (elem != NULL) {
+ ec = elem->getUint16(*us, 0);
+ }
+
+- return (ec == EC_Normal)?(EC_Normal):(DIMSE_PARSEFAILED);
++ return (ec.good())?(EC_Normal):(DIMSE_PARSEFAILED);
+ }
+
+ static OFCondition
+@@ -317,17 +321,19 @@ addUL(DcmDataset *obj, DcmTagKey t, Uint32 ul)
+ static OFCondition
+ getUL(DcmDataset *obj, DcmTagKey t, Uint32 *ul)
+ {
+- DcmElement *elem;
++ DcmElement *elem = NULL;
+ DcmStack stack;
+ OFCondition ec = EC_Normal;
+
+ ec = obj->search(t, stack);
+- elem = (DcmElement*)stack.top();
+- if (ec == EC_Normal && elem != NULL) {
++ if (ec.good() && stack.top()->isElement())
++ elem = (DcmElement*)stack.top();
++
++ if (elem != NULL) {
+ ec = elem->getUint32(*ul, 0);
+ }
+
+- return (ec == EC_Normal)?(EC_Normal):(DIMSE_PARSEFAILED);
++ return (ec.good())?(EC_Normal):(DIMSE_PARSEFAILED);
+ }
+
+ #if 0
+@@ -378,15 +384,17 @@ addAttributeList(DcmDataset *obj, DcmTagKey t, Uint16 *lst, int listCount)
+ static OFCondition
+ getAttributeList(DcmDataset *obj, DcmTagKey t, Uint16 **lst, int *listCount)
+ {
+- DcmElement *elem;
++ DcmElement *elem = NULL;
+ DcmStack stack;
+ OFCondition ec = EC_Normal;
+ Uint16 *aList = NULL;
+ Uint32 nBytes = 0;
+
+ ec = obj->search(t, stack);
+- elem = (DcmElement*)stack.top();
+- if (ec == EC_Normal && elem != NULL) {
++ if (ec.good() && stack.top()->isElement())
++ elem = (DcmElement*)stack.top();
++
++ if (elem) {
+ nBytes = elem->getLength();
+ *listCount = (int)(nBytes / sizeof(Uint16));
+ if (*listCount > 0) {
+@@ -398,7 +406,7 @@ getAttributeList(DcmDataset *obj, DcmTagKey t, Uint16 **lst, int *listCount)
+ }
+ }
+
+- return (ec == EC_Normal)?(EC_Normal):(DIMSE_PARSEFAILED);
++ return (ec.good())?(EC_Normal):(DIMSE_PARSEFAILED);
+ }
+
+ /*
+diff --git a/dcmnet/libsrc/diutil.cc b/dcmnet/libsrc/diutil.cc
+index 75111ae3bb..31c9645fcd 100644
+--- a/dcmnet/libsrc/diutil.cc
++++ b/dcmnet/libsrc/diutil.cc
+@@ -148,23 +148,21 @@ DU_stripLeadingAndTrailingSpaces(char *s)
+ OFBool
+ DU_getStringDOElement(DcmItem *obj, DcmTagKey t, char *s, size_t bufsize)
+ {
+- DcmByteString *elem;
+ DcmStack stack;
+- OFCondition ec = EC_Normal;
+ char* aString;
+
+- ec = obj->search(t, stack);
+- elem = (DcmByteString*) stack.top();
+- if (ec == EC_Normal && elem != NULL) {
++ OFCondition ec = obj->search(t, stack);
++ if (ec.good() && (stack.top() != NULL) && stack.top()->isElement()) {
++ DcmElement *elem = (DcmElement *) stack.top();
+ if (elem->getLength() == 0) {
+ s[0] = '\0';
+ } else {
+ ec = elem->getString(aString);
+- if (ec == EC_Normal)
++ if (ec.good())
+ OFStandard::strlcpy(s, aString, bufsize);
+ }
+ }
+- return (ec == EC_Normal);
++ return (ec.good());
+ }
+
+ OFBool
+@@ -182,7 +180,7 @@ DU_putStringDOElement(DcmItem *obj, DcmTagKey t, const char *s)
+ ec = obj->insert(e, OFTrue);
+ }
+
+- return (ec == EC_Normal);
++ return (ec.good());
+ }
+
+ OFBool
+@@ -190,15 +188,15 @@ DU_getShortDOElement(DcmItem *obj, DcmTagKey t, Uint16 *us)
+ {
+ DcmElement *elem;
+ DcmStack stack;
+- OFCondition ec = EC_Normal;
+
+- ec = obj->search(t, stack);
+- elem = (DcmElement*) stack.top();
+- if (ec == EC_Normal && elem != NULL) {
+- ec = elem->getUint16(*us, 0);
++ OFCondition ec = obj->search(t, stack);
++ if (ec.good() && stack.top()->isElement())
++ {
++ elem = (DcmElement*) stack.top();
++ if (elem) ec = elem->getUint16(*us, 0);
+ }
+
+- return (ec == EC_Normal);
++ return (ec.good());
+ }
+
+ OFBool
+@@ -215,7 +213,7 @@ DU_putShortDOElement(DcmItem *obj, DcmTagKey t, Uint16 us)
+ if (ec == EC_Normal) {
+ ec = obj->insert(e, OFTrue);
+ }
+- return (ec == EC_Normal);
++ return (ec.good());
+ }
+
+ OFBool
+diff --git a/dcmnet/libsrc/dstorscu.cc b/dcmnet/libsrc/dstorscu.cc
+index cbb3dcbe97..01024d5406 100644
+--- a/dcmnet/libsrc/dstorscu.cc
++++ b/dcmnet/libsrc/dstorscu.cc
+@@ -484,7 +484,7 @@ OFCondition DcmStorageSCU::addDicomFilesFromDICOMDIR(const OFFilename &filename,
+ OFFilename dirName;
+ OFStandard::getDirNameFromPath(dirName, filename, OFFalse /* assumeDirName */);
+ // iterate over all items (directory records) where ReferencedFileID is present
+- while (dataset->search(DCM_ReferencedFileID, stack, ESM_afterStackTop, OFTrue).good())
++ while (dataset->search(DCM_ReferencedFileID, stack, ESM_afterStackTop, OFTrue).good() && stack.top()->isElement())
+ {
+ // make sure that the dataset and element pointer are there
+ if (stack.card() > 1)
+diff --git a/dcmpstat/apps/dcmmklut.cc b/dcmpstat/apps/dcmmklut.cc
+index 044a17b3af..6a72ed3843 100644
+--- a/dcmpstat/apps/dcmmklut.cc
++++ b/dcmpstat/apps/dcmmklut.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2023, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -971,7 +971,7 @@ int main(int argc, char *argv[])
+ {
+ // search existing sequence
+ DcmStack stack;
+- if (EC_Normal == dataset->search(DCM_PresentationLUTSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dataset->search(DCM_PresentationLUTSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ dseq=(DcmSequenceOfItems *)stack.top();
+ }
+ if (dseq == NULL)
+@@ -992,7 +992,7 @@ int main(int argc, char *argv[])
+ {
+ // search existing sequence
+ DcmStack stack;
+- if (EC_Normal == dataset->search(DCM_VOILUTSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dataset->search(DCM_VOILUTSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ dseq=(DcmSequenceOfItems *)stack.top();
+ }
+ if (dseq == NULL)
+diff --git a/dcmpstat/apps/dcmpschk.cc b/dcmpstat/apps/dcmpschk.cc
+index ada6b164a3..12826b23f7 100644
+--- a/dcmpstat/apps/dcmpschk.cc
++++ b/dcmpstat/apps/dcmpschk.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 2000-2023, OFFIS e.V.
++ * Copyright (C) 2000-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -652,7 +652,11 @@ static OFString printAttribute(
+ OFOStringStream str;
+
+ ec = dset->search(key, stack, ESM_fromHere, OFFalse);
+- elem = (DcmElement*) stack.top();
++ if (ec.good() && stack.top()->isElement())
++ {
++ elem = (DcmElement*) stack.top();
++ }
++
+ if (elem)
+ elem->print(str, DCMTypes::PF_shortenLongTagValues);
+ else
+diff --git a/dcmpstat/libsrc/dviface.cc b/dcmpstat/libsrc/dviface.cc
+index 259e1580e0..d3a84510df 100644
+--- a/dcmpstat/libsrc/dviface.cc
++++ b/dcmpstat/libsrc/dviface.cc
+@@ -1417,14 +1417,14 @@ OFBool DVInterface::createPStateCache()
+ if (reference != NULL)
+ {
+ DcmStack stack;
+- if (dataset->search(DCM_ContentDescription, stack, ESM_fromHere, OFFalse) == EC_Normal)
++ if (dataset->search(DCM_ContentDescription, stack, ESM_fromHere, OFFalse) == EC_Normal && (stack.top()->ident() == EVR_LO))
+ {
+ char *value = NULL;
+ if ((*OFstatic_cast(DcmLongString *, stack.top())).getString(value) == EC_Normal)
+ reference->Description = value;
+ }
+ stack.clear();
+- if (dataset->search(DCM_ContentLabel, stack, ESM_fromHere, OFFalse) == EC_Normal)
++ if (dataset->search(DCM_ContentLabel, stack, ESM_fromHere, OFFalse) == EC_Normal && (stack.top()->ident() == EVR_LO))
+ {
+ char *value = NULL;
+ if ((*OFstatic_cast(DcmLongString *, stack.top())).getString(value) == EC_Normal)
+@@ -2835,12 +2835,12 @@ OFCondition DVInterface::saveFileFormatToDB(DcmFileFormat &fileformat)
+ DcmDataset *dset = fileformat.getDataset();
+ if (dset)
+ {
+- if (EC_Normal == dset->search(DCM_SOPInstanceUID, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset->search(DCM_SOPInstanceUID, stack, ESM_fromHere, OFFalse) && stack.top()->isElement())
+ {
+ OFstatic_cast(DcmElement *, stack.top())->getString(instanceUID);
+ }
+ stack.clear();
+- if (EC_Normal == dset->search(DCM_SOPClassUID, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset->search(DCM_SOPClassUID, stack, ESM_fromHere, OFFalse) && stack.top()->isElement())
+ {
+ OFstatic_cast(DcmElement *, stack.top())->getString(classUID);
+ }
+@@ -3756,7 +3756,7 @@ OFCondition DVInterface::addToPrintHardcopyFromDB(const char *studyUID, const ch
+ DVPSPresentationLUT presentationLUT;
+ if (EC_Normal != presentationLUT.read(*dataset, OFFalse)) presentationLUT.setType(DVPSP_identity);
+ result = dataset->search(sopclassuid.getTag(), stack, ESM_fromHere, OFFalse);
+- if (EC_Normal == result)
++ if (EC_Normal == result && (stack.top()->ident() == EVR_UI))
+ {
+ char *sopclass = NULL;
+ sopclassuid = *OFstatic_cast(DcmUniqueIdentifier *, stack.top());
+diff --git a/dcmpstat/libsrc/dvpsabl.cc b/dcmpstat/libsrc/dvpsabl.cc
+index 62cc1d51b9..bbda18183e 100644
+--- a/dcmpstat/libsrc/dvpsabl.cc
++++ b/dcmpstat/libsrc/dvpsabl.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1999-2010, OFFIS e.V.
++ * Copyright (C) 1999-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -69,7 +69,7 @@ OFCondition DVPSAnnotationContent_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_RETIRED_AnnotationContentSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_RETIRED_AnnotationContentSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmpstat/libsrc/dvpscu.cc b/dcmpstat/libsrc/dvpscu.cc
+index be3c81fe04..02a19452f1 100644
+--- a/dcmpstat/libsrc/dvpscu.cc
++++ b/dcmpstat/libsrc/dvpscu.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2020, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -80,14 +80,14 @@ OFCondition DVPSCurve::read(DcmItem &dset, Uint8 group)
+
+ /* first we look for the Curve Data */
+ DcmTagKey key(0x5000 + group,0x3000);
+- if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse) && stack.top()->isElement())
+ {
+ d_curveData = (DcmElement *)(stack.top());
+ } else return EC_IllegalCall;
+
+ key.setElement(0x0005); // Curve Dimensions
+ stack.clear();
+- if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse) && stack.top()->isElement())
+ {
+ d_curveDimensions = (DcmElement *)(stack.top());
+ } else return EC_IllegalCall;
+@@ -101,42 +101,42 @@ OFCondition DVPSCurve::read(DcmItem &dset, Uint8 group)
+
+ key.setElement(0x0010); // Number of Points
+ stack.clear();
+- if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse) && stack.top()->isElement())
+ {
+ d_numberOfPoints = (DcmElement *)(stack.top());
+ } else return EC_IllegalCall;
+
+ key.setElement(0x0020); // Type of Data
+ stack.clear();
+- if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse) && stack.top()->isElement())
+ {
+ d_typeOfData = (DcmElement *)(stack.top());
+ } else return EC_IllegalCall;
+
+ key.setElement(0x0103); // Data Value Representation
+ stack.clear();
+- if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse) && stack.top()->isElement())
+ {
+ d_dataVR = (DcmElement *)(stack.top());
+ } else return EC_IllegalCall;
+
+ key.setElement(0x0022); // Curve Description
+ stack.clear();
+- if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse) && stack.top()->isElement())
+ {
+ d_curveDescription = (DcmElement *)(stack.top());
+ }
+
+ key.setElement(0x0030); // Axis Units
+ stack.clear();
+- if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse) && stack.top()->isElement())
+ {
+ d_axisUnits = (DcmElement *)(stack.top());
+ }
+
+ key.setElement(0x2500); // Curve Label
+ stack.clear();
+- if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse) && stack.top()->isElement())
+ {
+ d_curveLabel = (DcmElement *)(stack.top());
+ }
+diff --git a/dcmpstat/libsrc/dvpsdal.cc b/dcmpstat/libsrc/dvpsdal.cc
+index 519aa977fd..969c182999 100644
+--- a/dcmpstat/libsrc/dvpsdal.cc
++++ b/dcmpstat/libsrc/dvpsdal.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1999-2010, OFFIS e.V.
++ * Copyright (C) 1999-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -67,7 +67,7 @@ OFCondition DVPSDisplayedArea_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_DisplayedAreaSelectionSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_DisplayedAreaSelectionSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmpstat/libsrc/dvpsfs.cc b/dcmpstat/libsrc/dvpsfs.cc
+index 5a5173c155..ba311b258e 100644
+--- a/dcmpstat/libsrc/dvpsfs.cc
++++ b/dcmpstat/libsrc/dvpsfs.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2021, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -280,7 +280,7 @@ OFBool DVPSFilmSession::printSCPCreate(
+ {
+ stack.clear();
+
+- if (rqDataset && (EC_Normal == rqDataset->search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_SQ))
+ {
+ DcmSequenceOfItems *seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+@@ -480,7 +480,7 @@ OFBool DVPSFilmSession::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)numberOfCopies.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)numberOfCopies.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_IS))
+ {
+ numberOfCopies = *((DcmIntegerString *)(stack.top()));
+ Sint32 numCopies=0;
+@@ -502,7 +502,7 @@ OFBool DVPSFilmSession::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)printPriority.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)printPriority.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ printPriority = *((DcmCodeString *)(stack.top()));
+ OFString aString;
+@@ -523,7 +523,7 @@ OFBool DVPSFilmSession::printSCPSet(
+ {
+ Uint32 numMediumTypes = cfg.getTargetPrinterNumberOfMediumTypes(cfgname);
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)mediumType.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)mediumType.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ mediumType = *((DcmCodeString *)(stack.top()));
+ OFString theMedium;
+@@ -555,7 +555,7 @@ OFBool DVPSFilmSession::printSCPSet(
+ {
+ Uint32 numFilmDestination = cfg.getTargetPrinterNumberOfFilmDestinations(cfgname);
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)filmDestination.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)filmDestination.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ filmDestination = *((DcmCodeString *)(stack.top()));
+ OFString theDestination;
+@@ -586,7 +586,7 @@ OFBool DVPSFilmSession::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)filmSessionLabel.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)filmSessionLabel.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_LO))
+ {
+ filmSessionLabel = *((DcmLongString *)(stack.top()));
+ ADD_TO_PDATASET(DcmLongString, filmSessionLabel)
+@@ -597,7 +597,7 @@ OFBool DVPSFilmSession::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)ownerID.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)ownerID.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_SH))
+ {
+ ownerID = *((DcmShortString *)(stack.top()));
+ ADD_TO_PDATASET(DcmShortString, ownerID)
+@@ -611,7 +611,7 @@ OFBool DVPSFilmSession::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)illumination.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)illumination.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ illumination = *((DcmUnsignedShort *)(stack.top()));
+ // we don't check illumination set by the user (for now)
+@@ -623,7 +623,7 @@ OFBool DVPSFilmSession::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)reflectedAmbientLight.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)reflectedAmbientLight.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ reflectedAmbientLight = *((DcmUnsignedShort *)(stack.top()));
+ // we don't check reflected ambient light set by the user (for now)
+@@ -636,7 +636,7 @@ OFBool DVPSFilmSession::printSCPSet(
+ {
+ stack.clear();
+
+- if (rqDataset && (EC_Normal == rqDataset->search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_SQ))
+ {
+ DcmSequenceOfItems *seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+diff --git a/dcmpstat/libsrc/dvpsgal.cc b/dcmpstat/libsrc/dvpsgal.cc
+index 909deac9e2..89d893de83 100644
+--- a/dcmpstat/libsrc/dvpsgal.cc
++++ b/dcmpstat/libsrc/dvpsgal.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2010, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -69,7 +69,7 @@ OFCondition DVPSGraphicAnnotation_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_GraphicAnnotationSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_GraphicAnnotationSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmpstat/libsrc/dvpsgll.cc b/dcmpstat/libsrc/dvpsgll.cc
+index d82d208628..fbf5d97d72 100644
+--- a/dcmpstat/libsrc/dvpsgll.cc
++++ b/dcmpstat/libsrc/dvpsgll.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2017, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -75,7 +75,7 @@ OFCondition DVPSGraphicLayer_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_GraphicLayerSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_GraphicLayerSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmpstat/libsrc/dvpsgrl.cc b/dcmpstat/libsrc/dvpsgrl.cc
+index 14d0e713f9..61dd6565c3 100644
+--- a/dcmpstat/libsrc/dvpsgrl.cc
++++ b/dcmpstat/libsrc/dvpsgrl.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2010, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -66,7 +66,7 @@ OFCondition DVPSGraphicObject_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_GraphicObjectSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_GraphicObjectSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmpstat/libsrc/dvpshlp.cc b/dcmpstat/libsrc/dvpshlp.cc
+index 20b4429e45..fd1057a137 100644
+--- a/dcmpstat/libsrc/dvpshlp.cc
++++ b/dcmpstat/libsrc/dvpshlp.cc
+@@ -163,7 +163,7 @@ OFBool DVPSHelper::haveReferencedUIDItem(DcmSequenceOfItems& seq, const char *ui
+ {
+ item = seq.getItem(i);
+ stack.clear();
+- if (EC_Normal == item->search(DCM_ReferencedSOPClassUID, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == item->search(DCM_ReferencedSOPClassUID, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_UI))
+ {
+ aString.clear();
+ refuid = (DcmUniqueIdentifier *)(stack.top());
+diff --git a/dcmpstat/libsrc/dvpsib.cc b/dcmpstat/libsrc/dvpsib.cc
+index 096c5b3e19..57fee5763b 100644
+--- a/dcmpstat/libsrc/dvpsib.cc
++++ b/dcmpstat/libsrc/dvpsib.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2018, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -153,7 +153,7 @@ OFCondition DVPSImageBoxContent::read(DcmItem &dset, DVPSPresentationLUT_PList&
+ if (result==EC_Normal)
+ {
+ stack.clear();
+- if (EC_Normal == dset.search(DCM_ReferencedImageSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_ReferencedImageSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+@@ -181,7 +181,7 @@ OFCondition DVPSImageBoxContent::read(DcmItem &dset, DVPSPresentationLUT_PList&
+ // check referenced presentation LUT sequence
+ // if there is any reference, it must refer to one of the presentation LUTs we are managing.
+ stack.clear();
+- if (EC_Normal == dset.search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+@@ -672,7 +672,7 @@ OFBool DVPSImageBoxContent::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)imageBoxPosition.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)imageBoxPosition.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ imageBoxPosition = *((DcmUnsignedShort *)(stack.top()));
+ // the image box position is checked elsewhere
+@@ -688,7 +688,7 @@ OFBool DVPSImageBoxContent::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)magnificationType.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)magnificationType.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ magnificationType = *((DcmCodeString *)(stack.top()));
+ Uint32 numMagnifications = cfg.getTargetPrinterNumberOfMagnificationTypes(cfgname);
+@@ -721,7 +721,7 @@ OFBool DVPSImageBoxContent::printSCPSet(
+ {
+
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)smoothingType.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)smoothingType.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ smoothingType = *((DcmCodeString *)(stack.top()));
+ Uint32 numSmoothings = cfg.getTargetPrinterNumberOfSmoothingTypes(cfgname);
+@@ -761,7 +761,7 @@ OFBool DVPSImageBoxContent::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)configurationInformation.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)configurationInformation.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_ST))
+ {
+ configurationInformation = *((DcmShortText *)(stack.top()));
+ Uint32 numConfigurationInformation = cfg.getTargetPrinterNumberOfConfigurationSettings(cfgname);
+@@ -800,7 +800,7 @@ OFBool DVPSImageBoxContent::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)polarity.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)polarity.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ polarity = *((DcmCodeString *)(stack.top()));
+ OFString thePolarity;
+@@ -820,7 +820,7 @@ OFBool DVPSImageBoxContent::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)requestedImageSize.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)requestedImageSize.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_DS))
+ {
+ if (! cfg.getTargetPrinterSupportsRequestedImageSize(cfgname))
+ {
+@@ -841,7 +841,7 @@ OFBool DVPSImageBoxContent::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)requestedDecimateCropBehavior.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)requestedDecimateCropBehavior.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ if (! cfg.getTargetPrinterSupportsDecimateCrop(cfgname))
+ {
+@@ -871,7 +871,7 @@ OFBool DVPSImageBoxContent::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search(DCM_BasicGrayscaleImageSequence, stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search(DCM_BasicGrayscaleImageSequence, stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_SQ))
+ {
+ DcmSequenceOfItems *seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+@@ -971,7 +971,7 @@ OFBool DVPSImageBoxContent::printSCPEvaluateBasicGrayscaleImageSequence(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)samplesPerPixel.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)samplesPerPixel.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ samplesPerPixel = *((DcmUnsignedShort *)(stack.top()));
+ val = 0;
+@@ -994,7 +994,7 @@ OFBool DVPSImageBoxContent::printSCPEvaluateBasicGrayscaleImageSequence(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)rows.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)rows.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ rows = *((DcmUnsignedShort *)(stack.top()));
+ val = 0;
+@@ -1017,7 +1017,7 @@ OFBool DVPSImageBoxContent::printSCPEvaluateBasicGrayscaleImageSequence(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)columns.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)columns.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ columns = *((DcmUnsignedShort *)(stack.top()));
+ val = 0;
+@@ -1042,7 +1042,7 @@ OFBool DVPSImageBoxContent::printSCPEvaluateBasicGrayscaleImageSequence(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)bitsStored.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)bitsStored.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ bitsStored = *((DcmUnsignedShort *)(stack.top()));
+ val = 0;
+@@ -1082,7 +1082,7 @@ OFBool DVPSImageBoxContent::printSCPEvaluateBasicGrayscaleImageSequence(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)bitsAllocated.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)bitsAllocated.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ bitsAllocated = *((DcmUnsignedShort *)(stack.top()));
+ val = 0;
+@@ -1105,7 +1105,7 @@ OFBool DVPSImageBoxContent::printSCPEvaluateBasicGrayscaleImageSequence(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)highBit.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)highBit.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ highBit = *((DcmUnsignedShort *)(stack.top()));
+ val = 0;
+@@ -1128,7 +1128,7 @@ OFBool DVPSImageBoxContent::printSCPEvaluateBasicGrayscaleImageSequence(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)pixelRepresentation.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)pixelRepresentation.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ pixelRepresentation = *((DcmUnsignedShort *)(stack.top()));
+ val = 0;
+@@ -1151,7 +1151,7 @@ OFBool DVPSImageBoxContent::printSCPEvaluateBasicGrayscaleImageSequence(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)photometricInterpretation.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)photometricInterpretation.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ photometricInterpretation = *((DcmCodeString *)(stack.top()));
+ OFString theColorModel;
+@@ -1175,7 +1175,7 @@ OFBool DVPSImageBoxContent::printSCPEvaluateBasicGrayscaleImageSequence(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)pixelAspectRatio.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)pixelAspectRatio.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_IS))
+ {
+ pixelAspectRatio = *((DcmIntegerString *)(stack.top()));
+ if (pixelAspectRatio.getVM() != 2)
+@@ -1193,7 +1193,7 @@ OFBool DVPSImageBoxContent::printSCPEvaluateBasicGrayscaleImageSequence(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search(DCM_PixelData, stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search(DCM_PixelData, stack, ESM_fromHere, OFFalse)) && stack.top()->isElement())
+ {
+ pixelData = new DcmPixelData(DCM_PixelData);
+ if (pixelData)
+diff --git a/dcmpstat/libsrc/dvpsibl.cc b/dcmpstat/libsrc/dvpsibl.cc
+index e3768d5a0d..ef069eb845 100644
+--- a/dcmpstat/libsrc/dvpsibl.cc
++++ b/dcmpstat/libsrc/dvpsibl.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1999-2010, OFFIS e.V.
++ * Copyright (C) 1999-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -68,7 +68,7 @@ OFCondition DVPSImageBoxContent_PList::read(DcmItem &dset, DVPSPresentationLUT_P
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_RETIRED_ImageBoxContentSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_RETIRED_ImageBoxContentSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmpstat/libsrc/dvpspll.cc b/dcmpstat/libsrc/dvpspll.cc
+index 1b2b7a35bb..46465171c7 100644
+--- a/dcmpstat/libsrc/dvpspll.cc
++++ b/dcmpstat/libsrc/dvpspll.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1999-2022, OFFIS e.V.
++ * Copyright (C) 1999-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -72,7 +72,7 @@ OFCondition DVPSPresentationLUT_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_RETIRED_PresentationLUTContentSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_RETIRED_PresentationLUTContentSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmpstat/libsrc/dvpsril.cc b/dcmpstat/libsrc/dvpsril.cc
+index 793e69063a..9dee1f6bfd 100644
+--- a/dcmpstat/libsrc/dvpsril.cc
++++ b/dcmpstat/libsrc/dvpsril.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2022, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -71,7 +71,7 @@ OFCondition DVPSReferencedImage_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_ReferencedImageSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_ReferencedImageSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmpstat/libsrc/dvpsrsl.cc b/dcmpstat/libsrc/dvpsrsl.cc
+index 4b0c83aa75..d2f9dcfffd 100644
+--- a/dcmpstat/libsrc/dvpsrsl.cc
++++ b/dcmpstat/libsrc/dvpsrsl.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2010, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -69,7 +69,7 @@ OFCondition DVPSReferencedSeries_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_ReferencedSeriesSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_ReferencedSeriesSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmpstat/libsrc/dvpssp.cc b/dcmpstat/libsrc/dvpssp.cc
+index 98b1201a7f..717c814607 100644
+--- a/dcmpstat/libsrc/dvpssp.cc
++++ b/dcmpstat/libsrc/dvpssp.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2021, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -328,7 +328,7 @@ OFCondition DVPSStoredPrint::read(DcmItem &dset)
+ if (result==EC_Normal)
+ {
+ stack.clear();
+- if (EC_Normal == dset.search(DCM_RETIRED_FilmBoxContentSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_RETIRED_FilmBoxContentSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+@@ -362,7 +362,7 @@ OFCondition DVPSStoredPrint::read(DcmItem &dset)
+ // check referenced presentation LUT sequence
+ // if there is any reference, it must refer to one of the presentation LUTs we are managing.
+ stack.clear();
+- if (EC_Normal == item->search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == item->search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+@@ -445,7 +445,7 @@ OFCondition DVPSStoredPrint::read(DcmItem &dset)
+ if (result==EC_Normal)
+ {
+ stack.clear();
+- if (EC_Normal == dset.search(DCM_RETIRED_PrintManagementCapabilitiesSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_RETIRED_PrintManagementCapabilitiesSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ OFBool haveFilmBox = OFFalse;
+ OFBool haveGrayscaleImageBox = OFFalse;
+@@ -511,7 +511,7 @@ OFCondition DVPSStoredPrint::read(DcmItem &dset)
+ destination.clear();
+ printerName.clear();
+ stack.clear();
+- if (EC_Normal == dset.search(DCM_RETIRED_PrinterCharacteristicsSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_RETIRED_PrinterCharacteristicsSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ seq = (DcmSequenceOfItems *)stack.top();
+ if (seq->card() > 0)
+@@ -1536,7 +1536,7 @@ OFCondition DVPSStoredPrint::printSCUcreateBasicFilmBox(DVPSPrintMessageHandler&
+ {
+ // N-CREATE was successful, now evaluate Referenced Image Box SQ
+ stack.clear();
+- if (EC_Normal == attributeListOut->search(DCM_ReferencedImageBoxSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == attributeListOut->search(DCM_ReferencedImageBoxSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ seq=(DcmSequenceOfItems *)stack.top();
+ numItems = (size_t)seq->card();
+@@ -1559,7 +1559,7 @@ OFCondition DVPSStoredPrint::printSCUcreateBasicFilmBox(DVPSPrintMessageHandler&
+ // evaluate Referenced Basic Annotation Box SQ if present
+ stack.clear();
+ annotationContentList.clearAnnotationSOPInstanceUIDs();
+- if (EC_Normal == attributeListOut->search(DCM_ReferencedBasicAnnotationBoxSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == attributeListOut->search(DCM_ReferencedBasicAnnotationBoxSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ seq=(DcmSequenceOfItems *)stack.top();
+ numItems = (size_t)seq->card();
+@@ -2419,7 +2419,7 @@ OFBool DVPSStoredPrint::printSCPCreate(
+ {
+ stack.clear();
+
+- if (rqDataset && (EC_Normal == rqDataset->search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_SQ))
+ {
+ DcmSequenceOfItems *seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+@@ -2487,7 +2487,7 @@ OFBool DVPSStoredPrint::printSCPCreate(
+ {
+ stack.clear();
+
+- if (rqDataset && (EC_Normal == rqDataset->search(DCM_ReferencedFilmSessionSequence, stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search(DCM_ReferencedFilmSessionSequence, stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_SQ))
+ {
+ DcmUniqueIdentifier classUID(DCM_ReferencedSOPClassUID);
+ DcmUniqueIdentifier instanceUID(DCM_ReferencedSOPInstanceUID);
+@@ -2706,7 +2706,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)magnificationType.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)magnificationType.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ magnificationType = *((DcmCodeString *)(stack.top()));
+ Uint32 numMagnifications = cfg.getTargetPrinterNumberOfMagnificationTypes(cfgname);
+@@ -2739,7 +2739,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ {
+
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)smoothingType.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)smoothingType.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ smoothingType = *((DcmCodeString *)(stack.top()));
+ Uint32 numSmoothings = cfg.getTargetPrinterNumberOfSmoothingTypes(cfgname);
+@@ -2781,7 +2781,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ {
+
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)borderDensity.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)borderDensity.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ borderDensity = *((DcmCodeString *)(stack.top()));
+ Uint32 numBorderDensities = cfg.getTargetPrinterNumberOfBorderDensities(cfgname);
+@@ -2832,7 +2832,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)emptyImageDensity.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)emptyImageDensity.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ emptyImageDensity = *((DcmCodeString *)(stack.top()));
+ Uint32 numEmptyImageDensities = cfg.getTargetPrinterNumberOfEmptyImageDensities(cfgname);
+@@ -2883,7 +2883,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)maxDensity.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)maxDensity.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ maxDensity = *((DcmUnsignedShort *)(stack.top()));
+ // we don't check a max density set by the user (for now)
+@@ -2895,7 +2895,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)minDensity.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)minDensity.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ minDensity = *((DcmUnsignedShort *)(stack.top()));
+ Uint32 numMinDensities = cfg.getTargetPrinterNumberOfMinDensities(cfgname);
+@@ -2917,7 +2917,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)trim.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)trim.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_CS))
+ {
+ trim = *((DcmCodeString *)(stack.top()));
+
+@@ -2945,7 +2945,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)configurationInformation.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)configurationInformation.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_ST))
+ {
+ configurationInformation = *((DcmShortText *)(stack.top()));
+ Uint32 numConfigurationInformation = cfg.getTargetPrinterNumberOfConfigurationSettings(cfgname);
+@@ -2987,7 +2987,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)illumination.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)illumination.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ illumination = *((DcmUnsignedShort *)(stack.top()));
+ // we don't check illumination set by the user (for now)
+@@ -2999,7 +2999,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ if (result)
+ {
+ stack.clear();
+- if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)reflectedAmbientLight.getTag(), stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search((DcmTagKey &)reflectedAmbientLight.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
+ {
+ reflectedAmbientLight = *((DcmUnsignedShort *)(stack.top()));
+ // we don't check reflected ambient light set by the user (for now)
+@@ -3012,7 +3012,7 @@ OFBool DVPSStoredPrint::printSCPSet(
+ {
+ stack.clear();
+
+- if (rqDataset && (EC_Normal == rqDataset->search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse)))
++ if (rqDataset && (EC_Normal == rqDataset->search(DCM_ReferencedPresentationLUTSequence, stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_SQ))
+ {
+ DcmSequenceOfItems *seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+diff --git a/dcmpstat/libsrc/dvpstxl.cc b/dcmpstat/libsrc/dvpstxl.cc
+index ffb6dcc10e..8e35ff7ae6 100644
+--- a/dcmpstat/libsrc/dvpstxl.cc
++++ b/dcmpstat/libsrc/dvpstxl.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2010, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -66,7 +66,7 @@ OFCondition DVPSTextObject_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_TextObjectSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_TextObjectSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmpstat/libsrc/dvpsvll.cc b/dcmpstat/libsrc/dvpsvll.cc
+index 3859f4ab96..17a6277071 100644
+--- a/dcmpstat/libsrc/dvpsvll.cc
++++ b/dcmpstat/libsrc/dvpsvll.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2010, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -66,7 +66,7 @@ OFCondition DVPSVOILUT_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_VOILUTSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_VOILUTSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+diff --git a/dcmrt/libsrc/drttypes.cc b/dcmrt/libsrc/drttypes.cc
+index 3aee4312f2..77ff1674c6 100644
+--- a/dcmrt/libsrc/drttypes.cc
++++ b/dcmrt/libsrc/drttypes.cc
+@@ -1,14 +1,12 @@
+ /*
+ *
+- * Copyright (c) 2008-2021, OFFIS e.V. and ICSMED AG, Oldenburg, Germany
+- * Copyright (C) 2013-2021, J. Riesmeier, Oldenburg, Germany
++ * Copyright (c) 2008-2024, OFFIS e.V. and ICSMED AG, Oldenburg, Germany
++ * Copyright (C) 2013-2024, J. Riesmeier, Oldenburg, Germany
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * Source file for class DRTTypes
+ *
+ * Generated manually based on dsrtypes.cc
+- * File created on 2008-12-05
+- * Last modified on 2016-02-12 by Riesmeier
+ *
+ */
+
+@@ -212,7 +210,7 @@ OFCondition DRTTypes::getAndCheckStringValueFromDataset(DcmItem &dataset,
+ {
+ DcmStack stack;
+ OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+- if (result.good())
++ if (result.good() && stack.top()->isElement())
+ {
+ DcmElement *element = OFstatic_cast(DcmElement *, stack.top());
+ if (element != NULL)
+diff --git a/dcmsign/libsrc/dcsignat.cc b/dcmsign/libsrc/dcsignat.cc
+index b104ec1e81..c5b57099a4 100644
+--- a/dcmsign/libsrc/dcsignat.cc
++++ b/dcmsign/libsrc/dcsignat.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 2000-2023, OFFIS e.V.
++ * Copyright (C) 2000-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -104,7 +104,7 @@ OFCondition DcmSignature::getMACIDnumber(DcmItem &item, Uint16& macid)
+ macid = 0xFFFF;
+ DcmStack stack;
+ OFCondition result = item.search(DCM_MACIDNumber, stack, ESM_fromHere, OFFalse);
+- if (result.good() && (stack.top()->isLeaf()))
++ if (result.good() && (stack.top()->isElement()))
+ {
+ result = ((DcmElement *)(stack.top()))->getUint16(macid);
+ }
+@@ -734,7 +734,7 @@ OFCondition DcmSignature::verifyCurrent()
+ // read MAC Calculation Transfer Syntax UID
+ if (result.good())
+ {
+- if ((selectedMacParametersItem->search(DCM_MACCalculationTransferSyntaxUID, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isLeaf()))
++ if ((selectedMacParametersItem->search(DCM_MACCalculationTransferSyntaxUID, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isElement()))
+ {
+ char *uid = NULL;
+ if ((((DcmElement *)(stack.top()))->getString(uid)).good())
+@@ -750,7 +750,7 @@ OFCondition DcmSignature::verifyCurrent()
+ if (result.good())
+ {
+ stack.clear();
+- if ((selectedMacParametersItem->search(DCM_MACAlgorithm, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isLeaf()))
++ if ((selectedMacParametersItem->search(DCM_MACAlgorithm, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isElement()))
+ {
+ OFString macidentifier;
+ if ((((DcmElement *)(stack.top()))->getOFString(macidentifier, 0)).good())
+@@ -783,7 +783,7 @@ OFCondition DcmSignature::verifyCurrent()
+ if (result.good())
+ {
+ stack.clear();
+- if ((selectedSignatureItem->search(DCM_Signature, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isLeaf()))
++ if ((selectedSignatureItem->search(DCM_Signature, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->ident() == EVR_OB))
+ {
+ signature = new DcmOtherByteOtherWord(*((DcmOtherByteOtherWord *)(stack.top())));
+ if (signature == NULL) result = EC_MemoryExhausted;
+@@ -960,7 +960,7 @@ OFCondition DcmSignature::getCurrentMacXferSyntaxName(OFString& str)
+ DcmStack stack;
+
+ // read MAC Calculation Transfer Syntax UID
+- if ((selectedMacParametersItem->search(DCM_MACCalculationTransferSyntaxUID, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isLeaf()))
++ if ((selectedMacParametersItem->search(DCM_MACCalculationTransferSyntaxUID, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isElement()))
+ {
+ char *uid = NULL;
+ if ((((DcmElement *)(stack.top()))->getString(uid)).good() && uid)
+@@ -1005,7 +1005,7 @@ OFCondition DcmSignature::getCurrentMacName(OFString& str)
+ DcmStack stack;
+
+ // read MAC Algorithm
+- if ((selectedMacParametersItem->search(DCM_MACAlgorithm, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isLeaf()))
++ if ((selectedMacParametersItem->search(DCM_MACAlgorithm, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isElement()))
+ {
+ if ((((DcmElement *)(stack.top()))->getOFString(str, 0)).good()) result = EC_Normal;
+ }
+@@ -1020,7 +1020,7 @@ OFCondition DcmSignature::getCurrentSignatureUID(OFString& str)
+ DcmStack stack;
+
+ // read signature UID
+- if ((selectedSignatureItem->search(DCM_DigitalSignatureUID, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isLeaf()))
++ if ((selectedSignatureItem->search(DCM_DigitalSignatureUID, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isElement()))
+ {
+ if ((((DcmElement *)(stack.top()))->getOFString(str, 0)).good()) result = EC_Normal;
+ }
+@@ -1048,7 +1048,7 @@ OFCondition DcmSignature::getCurrentSignatureDateTime(OFString& str)
+ DcmStack stack;
+
+ // read signature date/time
+- if ((selectedSignatureItem->search(DCM_DigitalSignatureDateTime, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isLeaf()))
++ if ((selectedSignatureItem->search(DCM_DigitalSignatureDateTime, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isElement()))
+ {
+ if ((((DcmElement *)(stack.top()))->getOFString(str, 0)).good()) result = EC_Normal;
+ }
+@@ -1119,7 +1119,7 @@ OFCondition DcmSignature::verifySignatureProfile(SiSecurityProfile &sprof)
+ // check MAC Calculation Transfer Syntax UID
+ if (result.good())
+ {
+- if ((selectedMacParametersItem->search(DCM_MACCalculationTransferSyntaxUID, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isLeaf()))
++ if ((selectedMacParametersItem->search(DCM_MACCalculationTransferSyntaxUID, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isElement()))
+ {
+ char *uid = NULL;
+ if ((((DcmElement *)(stack.top()))->getString(uid)).good())
+@@ -1142,7 +1142,7 @@ OFCondition DcmSignature::verifySignatureProfile(SiSecurityProfile &sprof)
+ {
+ E_MACType mac = EMT_RIPEMD160;
+ stack.clear();
+- if ((selectedMacParametersItem->search(DCM_MACAlgorithm, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isLeaf()))
++ if ((selectedMacParametersItem->search(DCM_MACAlgorithm, stack, ESM_fromHere, OFFalse)).good() && (stack.top()->isElement()))
+ {
+ OFString macidentifier;
+ if ((((DcmElement *)(stack.top()))->getOFString(macidentifier, 0)).good())
+diff --git a/dcmsign/libsrc/sicert.cc b/dcmsign/libsrc/sicert.cc
+index 173bbbf2c3..0668b72c99 100644
+--- a/dcmsign/libsrc/sicert.cc
++++ b/dcmsign/libsrc/sicert.cc
+@@ -135,7 +135,7 @@ OFCondition SiCertificate::read(DcmItem& item)
+ OFString aString;
+ DcmStack stack;
+ result = item.search(DCM_CertificateType, stack, ESM_fromHere, OFFalse);
+- if (result.good())
++ if (result.good() && stack.top()->isElement())
+ {
+ result = ((DcmElement *)(stack.top()))->getOFString(aString, 0);
+ if (result.good())
+@@ -144,7 +144,7 @@ OFCondition SiCertificate::read(DcmItem& item)
+ {
+ stack.clear();
+ result = item.search(DCM_CertificateOfSigner, stack, ESM_fromHere, OFFalse);
+- if (result.good())
++ if (result.good() && stack.top()->isElement())
+ {
+ DcmElement *cert = (DcmElement *)stack.top();
+ Uint8 *data = NULL;
+diff --git a/dcmsr/libsrc/dsrtypes.cc b/dcmsr/libsrc/dsrtypes.cc
+index 08414ad93e..a9d6218594 100644
+--- a/dcmsr/libsrc/dsrtypes.cc
++++ b/dcmsr/libsrc/dsrtypes.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 2000-2023, OFFIS e.V.
++ * Copyright (C) 2000-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -1178,7 +1178,7 @@ OFCondition DSRTypes::getAndCheckElementFromDataset(DcmItem &dataset,
+ DcmStack stack;
+ const DcmTagKey tagKey = delem.getTag();
+ OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+- if (result.good())
++ if (result.good() && stack.top()->isElement())
+ {
+ /* copy object from search stack */
+ result = delem.copyFrom(*stack.top());
+@@ -1203,7 +1203,7 @@ OFCondition DSRTypes::getAndCheckStringValueFromDataset(DcmItem &dataset,
+ {
+ DcmStack stack;
+ OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+- if (result.good())
++ if (result.good() && stack.top()->isElement())
+ {
+ DcmElement *delem = OFstatic_cast(DcmElement *, stack.top());
+ /* we need a reference to the original element in order to determine the SpecificCharacterSet */
=====================================
debian/patches/0002-Fixed-unchecked-typecasts-and-fixed-LUT-handling.patch
=====================================
@@ -0,0 +1,503 @@
+From 601b227eecaab33a3a3a11dc256d84b1a62f63af Mon Sep 17 00:00:00 2001
+From: Marco Eichelberg <dicom at offis.de>
+Date: Mon, 15 Apr 2024 12:19:33 +0200
+Subject: [PATCH] Fixed unchecked typecasts and fixed LUT handling.
+
+This commit adds further fixes for unchecked typecasts of DcmItem::search()
+results (see description of previous commit). Furthermore, this commit
+specifically addresses the handling of look-up tables (LUTs) in module
+dcmpstat, where attribute (0028,3006) LUTData may use either US or OW
+value representation, and (0028,3002) LUTDescriptor may be either US or SS.
+The code should now properly handle all permitted value representations.
+LUTData is now always written as OW in order to avoid the 64k size limit
+for US in explicit VR encoding.
+
+Thanks to Martin Zeiser from the Cisco Talos team
+<vulndiscovery at external.cisco.com> for the bug report (TALOS-2024-1957).
+
+Together with the previous commit, this closes DCMTK issue #1120.
+---
+ dcmpstat/libsrc/dcmpstat.cc | 40 ++++++++++++++++-------
+ dcmpstat/libsrc/dvpspl.cc | 34 +++++++++++++------
+ dcmpstat/libsrc/dvpssv.cc | 34 +++++++++++++------
+ dcmpstat/libsrc/dvpssvl.cc | 25 +++++++++-----
+ dcmpstat/libsrc/dvpstat.cc | 65 +++++++++++++++++--------------------
+ dcmpstat/libsrc/dvpsvl.cc | 19 +++++++++--
+ 6 files changed, 139 insertions(+), 78 deletions(-)
+
+diff --git a/dcmpstat/libsrc/dcmpstat.cc b/dcmpstat/libsrc/dcmpstat.cc
+index 4a8e5af6c3..a7d11abaca 100644
+--- a/dcmpstat/libsrc/dcmpstat.cc
++++ b/dcmpstat/libsrc/dcmpstat.cc
+@@ -384,12 +384,16 @@ OFCondition DcmPresentationState::read(DcmItem &dset)
+ {
+ item = seq->getItem(0);
+ stack.clear();
+- // LUTDescriptor can be US or SS. For now we only handle US.
++
++ // LUTDescriptor can be US or SS
+ if ((EC_Normal == item->search((DcmTagKey &)modalityLUTDescriptor.getTag(),
+- stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
++ stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_SS))
+ {
+- modalityLUTDescriptor = *((DcmUnsignedShort *)(stack.top()));
++ // We explicitly use DcmElement::operator=(), which works for US and SS
++ DcmElement *mLUTDescriptor = &modalityLUTDescriptor;
++ mLUTDescriptor->operator=(* OFstatic_cast(DcmElement *, stack.top()));
+ }
++
+ stack.clear();
+ if ((EC_Normal == item->search((DcmTagKey &)modalityLUTExplanation.getTag(),
+ stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_LO))
+@@ -400,9 +404,11 @@ OFCondition DcmPresentationState::read(DcmItem &dset)
+
+ // LUTData can be OW, US or SS. For now we only handle US.
+ if ((EC_Normal == item->search((DcmTagKey &)modalityLUTData.getTag(),
+- stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
++ stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_OW))
+ {
+- modalityLUTData = *((DcmUnsignedShort *)(stack.top()));
++ // we deliberately call DcmElement::operator=() here, which will work for both DcmUnsignedShort and DcmOtherByteOtherWord parameters
++ DcmElement *mdata = &modalityLUTData;
++ mdata->operator=(*(DcmElement *)(stack.top()));
+ }
+ stack.clear();
+ if ((EC_Normal == item->search((DcmTagKey &)modalityLUTType.getTag(),
+@@ -879,11 +885,13 @@ OFCondition DcmPresentationState::createFromImage(
+ {
+ item = seq->getItem(0);
+ stack.clear();
+- // LUTDescriptor can be US or SS. For now we only handle US.
++ // LUTDescriptor can be US or SS
+ if ((EC_Normal == item->search((DcmTagKey &)modalityLUTDescriptor.getTag(),
+- stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
++ stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_SS))
+ {
+- modalityLUTDescriptor = *((DcmUnsignedShort *)(stack.top()));
++ // We explicitly use DcmElement::operator=(), which works for US and SS
++ DcmElement *mLUTDescriptor = &modalityLUTDescriptor;
++ mLUTDescriptor->operator=(* OFstatic_cast(DcmElement *, stack.top()));
+ }
+ stack.clear();
+ if ((EC_Normal == item->search((DcmTagKey &)modalityLUTExplanation.getTag(),
+@@ -895,9 +903,11 @@ OFCondition DcmPresentationState::createFromImage(
+
+ // LUTData can be OW, US or SS. For now we only handle US.
+ if ((EC_Normal == item->search((DcmTagKey &)modalityLUTData.getTag(),
+- stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US))
++ stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_OW))
+ {
+- modalityLUTData = *((DcmUnsignedShort *)(stack.top()));
++ // we deliberately call DcmElement::operator=() here, which will work for both DcmUnsignedShort and DcmOtherByteOtherWord parameters
++ DcmElement *mdata = &modalityLUTData;
++ mdata->operator=(*(DcmElement *)(stack.top()));
+ }
+ stack.clear();
+ if ((EC_Normal == item->search((DcmTagKey &)modalityLUTType.getTag(),
+@@ -1247,10 +1257,16 @@ OFCondition DcmPresentationState::write(DcmItem &dset, OFBool replaceSOPInstance
+ dseq = new DcmSequenceOfItems(DCM_ModalityLUTSequence);
+ if (dseq)
+ {
+- delem = new DcmUnsignedShort(modalityLUTDescriptor);
++ // we clone modalityLUTDescriptor in order to retain the VR (US or SS)
++ delem = OFstatic_cast(DcmElement *, modalityLUTDescriptor.clone());
+ if (delem) ditem->insert(delem, OFTrue /*replaceOld*/); else result=EC_MemoryExhausted;
+- delem = new DcmUnsignedShort(modalityLUTData);
++
++ // we write LUTData as OW in order to avoid the 64 kByte limit for US
++ delem = new DcmOtherByteOtherWord(DCM_LUTData);
++ delem->operator=(modalityLUTData);
++ OFstatic_cast(DcmOtherByteOtherWord *, delem)->setVR(EVR_OW);
+ if (delem) ditem->insert(delem, OFTrue /*replaceOld*/); else result=EC_MemoryExhausted;
++
+ delem = new DcmLongString(modalityLUTType);
+ if (delem) ditem->insert(delem, OFTrue /*replaceOld*/); else result=EC_MemoryExhausted;
+ if (modalityLUTExplanation.getLength() >0)
+diff --git a/dcmpstat/libsrc/dvpspl.cc b/dcmpstat/libsrc/dvpspl.cc
+index ec4cccf973..f5574ab337 100644
+--- a/dcmpstat/libsrc/dvpspl.cc
++++ b/dcmpstat/libsrc/dvpspl.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1999-2018, OFFIS e.V.
++ * Copyright (C) 1999-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -24,6 +24,7 @@
+ #include "dcmtk/dcmdata/dcdeftag.h"
+ #include "dcmtk/dcmdata/dcsequen.h"
+ #include "dcmtk/dcmdata/dcvrcs.h"
++#include "dcmtk/dcmdata/dcvrobow.h"
+ #include "dcmtk/dcmpstat/dvpspl.h"
+ #include "dcmtk/dcmpstat/dvpsdef.h" /* for constants and macros */
+ #include "dcmtk/dcmnet/dimse.h"
+@@ -79,29 +80,36 @@ OFCondition DVPSPresentationLUT::read(DcmItem &dset, OFBool withSOPInstance)
+ if (result==EC_Normal)
+ {
+ stack.clear();
+- if (EC_Normal == dset.search(DCM_PresentationLUTSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_PresentationLUTSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+ {
+ item = seq->getItem(0);
+ stack.clear();
+- if (EC_Normal == item->search((DcmTagKey &)presentationLUTDescriptor.getTag(),
+- stack, ESM_fromHere, OFFalse))
++
++ // LUTDescriptor can be US or SS
++ if ((EC_Normal == item->search((DcmTagKey &)presentationLUTDescriptor.getTag(),
++ stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_SS))
+ {
+- presentationLUTDescriptor = *((DcmUnsignedShort *)(stack.top()));
++ // We explicitly use DcmElement::operator=(), which works for US and SS
++ DcmElement *pLUTDescriptor = &presentationLUTDescriptor;
++ pLUTDescriptor->operator=(* OFstatic_cast(DcmElement *, stack.top()));
+ }
++
+ stack.clear();
+ if (EC_Normal == item->search((DcmTagKey &)presentationLUTExplanation.getTag(),
+- stack, ESM_fromHere, OFFalse))
++ stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_LO))
+ {
+ presentationLUTExplanation = *((DcmLongString *)(stack.top()));
+ }
+ stack.clear();
+ if (EC_Normal == item->search((DcmTagKey &)presentationLUTData.getTag(),
+- stack, ESM_fromHere, OFFalse))
++ stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_OW))
+ {
+- presentationLUTData = *((DcmUnsignedShort *)(stack.top()));
++ // we deliberately call DcmElement::operator=() here, which will work for both DcmUnsignedShort and DcmOtherByteOtherWord parameters
++ DcmElement *pldata = &presentationLUTData;
++ pldata->operator=(*(DcmElement *)(stack.top()));
+ }
+ } else {
+ result=EC_TagNotFound;
+@@ -187,10 +195,16 @@ OFCondition DVPSPresentationLUT::write(DcmItem &dset, OFBool withSOPInstance)
+ dseq = new DcmSequenceOfItems(DCM_PresentationLUTSequence);
+ if (dseq)
+ {
+- delem = new DcmUnsignedShort(presentationLUTDescriptor);
++ // we clone presentationLUTDescriptor in order to retain the VR (US or SS)
++ delem = OFstatic_cast(DcmElement *, presentationLUTDescriptor.clone());
+ if (delem) ditem->insert(delem, OFTrue /*replaceOld*/); else result=EC_MemoryExhausted;
+- delem = new DcmUnsignedShort(presentationLUTData);
++
++ // we write LUTData as OW in order to avoid the 64 kByte limit for US
++ delem = new DcmOtherByteOtherWord(DCM_LUTData);
++ delem->operator=(presentationLUTData);
++ OFstatic_cast(DcmOtherByteOtherWord *, delem)->setVR(EVR_OW);
+ if (delem) ditem->insert(delem, OFTrue /*replaceOld*/); else result=EC_MemoryExhausted;
++
+ if (presentationLUTExplanation.getLength() >0)
+ {
+ delem = new DcmLongString(presentationLUTExplanation);
+diff --git a/dcmpstat/libsrc/dvpssv.cc b/dcmpstat/libsrc/dvpssv.cc
+index 8e3d49bd4f..4a7fd0e309 100644
+--- a/dcmpstat/libsrc/dvpssv.cc
++++ b/dcmpstat/libsrc/dvpssv.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2018, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -23,6 +23,7 @@
+ #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
+ #include "dcmtk/dcmdata/dcdeftag.h"
+ #include "dcmtk/dcmdata/dcsequen.h"
++#include "dcmtk/dcmdata/dcvrobow.h"
+ #include "dcmtk/dcmpstat/dvpssv.h"
+ #include "dcmtk/dcmpstat/dvpsri.h" /* for DVPSReferencedImage */
+ #include "dcmtk/dcmpstat/dvpsrsl.h" /* DVPSReferencedSeries_PList */
+@@ -75,29 +76,36 @@ OFCondition DVPSSoftcopyVOI::read(DcmItem &dset)
+ if (result==EC_Normal)
+ {
+ stack.clear();
+- if (EC_Normal == dset.search(DCM_VOILUTSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_VOILUTSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() ==1)
+ {
+ item = seq->getItem(0);
+ stack.clear();
+- if (EC_Normal == item->search((DcmTagKey &)voiLUTDescriptor.getTag(),
+- stack, ESM_fromHere, OFFalse))
++
++ // LUTDescriptor can be US or SS
++ if ((EC_Normal == item->search((DcmTagKey &)voiLUTDescriptor.getTag(),
++ stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_SS))
+ {
+- voiLUTDescriptor = *((DcmUnsignedShort *)(stack.top()));
++ // We explicitly use DcmElement::operator=(), which works for US and SS
++ DcmElement *vLUTDescriptor = &voiLUTDescriptor;
++ vLUTDescriptor->operator=(* OFstatic_cast(DcmElement *, stack.top()));
+ }
++
+ stack.clear();
+ if (EC_Normal == item->search((DcmTagKey &)voiLUTExplanation.getTag(),
+- stack, ESM_fromHere, OFFalse))
++ stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_LO))
+ {
+ voiLUTExplanation = *((DcmLongString *)(stack.top()));
+ }
+ stack.clear();
+ if (EC_Normal == item->search((DcmTagKey &)voiLUTData.getTag(),
+- stack, ESM_fromHere, OFFalse))
++ stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_OW))
+ {
+- voiLUTData = *((DcmUnsignedShort *)(stack.top()));
++ // we deliberately call DcmElement::operator=() here, which will work for both DcmUnsignedShort and DcmOtherByteOtherWord parameters
++ DcmElement *vldata = &voiLUTData;
++ vldata->operator=(*(DcmElement *)(stack.top()));
+ }
+ } else {
+ result=EC_TagNotFound;
+@@ -177,10 +185,16 @@ OFCondition DVPSSoftcopyVOI::write(DcmItem &dset)
+ dseq = new DcmSequenceOfItems(DCM_VOILUTSequence);
+ if (dseq)
+ {
+- delem = new DcmUnsignedShort(voiLUTDescriptor);
++ // we clone voiLUTDescriptor in order to retain the VR (US or SS)
++ delem = OFstatic_cast(DcmElement *, voiLUTDescriptor.clone());
+ if (delem) ditem->insert(delem, OFTrue /*replaceOld*/); else result=EC_MemoryExhausted;
+- delem = new DcmUnsignedShort(voiLUTData);
++
++ // we write LUTData as OW in order to avoid the 64 kByte limit for US
++ delem = new DcmOtherByteOtherWord(DCM_LUTData);
++ delem->operator=(voiLUTData);
++ OFstatic_cast(DcmOtherByteOtherWord *, delem)->setVR(EVR_OW);
+ if (delem) ditem->insert(delem, OFTrue /*replaceOld*/); else result=EC_MemoryExhausted;
++
+ if (voiLUTExplanation.getLength() >0)
+ {
+ delem = new DcmLongString(voiLUTExplanation);
+diff --git a/dcmpstat/libsrc/dvpssvl.cc b/dcmpstat/libsrc/dvpssvl.cc
+index d1532db5c2..efcb6a26be 100644
+--- a/dcmpstat/libsrc/dvpssvl.cc
++++ b/dcmpstat/libsrc/dvpssvl.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1999-2023, OFFIS e.V.
++ * Copyright (C) 1999-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -72,7 +72,7 @@ OFCondition DVPSSoftcopyVOI_PList::read(DcmItem &dset)
+ DcmSequenceOfItems *dseq=NULL;
+ DcmItem *ditem=NULL;
+
+- if (EC_Normal == dset.search(DCM_SoftcopyVOILUTSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_SoftcopyVOILUTSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ dseq=(DcmSequenceOfItems *)stack.top();
+ if (dseq)
+@@ -249,29 +249,36 @@ OFCondition DVPSSoftcopyVOI_PList::createFromImage(
+ if (result==EC_Normal)
+ {
+ stack.clear();
+- if (EC_Normal == dset.search(DCM_VOILUTSequence, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dset.search(DCM_VOILUTSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
+ {
+ seq=(DcmSequenceOfItems *)stack.top();
+ if (seq->card() > 0)
+ {
+ item = seq->getItem(0);
+ stack.clear();
+- if (EC_Normal == item->search((DcmTagKey &)voiLUTDescriptor.getTag(),
+- stack, ESM_fromHere, OFFalse))
++
++ // LUTDescriptor can be US or SS
++ if ((EC_Normal == item->search((DcmTagKey &)voiLUTDescriptor.getTag(),
++ stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_SS))
+ {
+- voiLUTDescriptor = *((DcmUnsignedShort *)(stack.top()));
++ // We explicitly use DcmElement::operator=(), which works for US and SS
++ DcmElement *vLUTDescriptor = &voiLUTDescriptor;
++ vLUTDescriptor->operator=(* OFstatic_cast(DcmElement *, stack.top()));
+ }
++
+ stack.clear();
+ if (EC_Normal == item->search((DcmTagKey &)voiLUTExplanation.getTag(),
+- stack, ESM_fromHere, OFFalse))
++ stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_LO))
+ {
+ voiLUTExplanation = *((DcmLongString *)(stack.top()));
+ }
+ stack.clear();
+ if (EC_Normal == item->search((DcmTagKey &)voiLUTData.getTag(),
+- stack, ESM_fromHere, OFFalse))
++ stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_OW))
+ {
+- voiLUTData = *((DcmUnsignedShort *)(stack.top()));
++ // we deliberately call DcmElement::operator=() here, which will work for both DcmUnsignedShort and DcmOtherByteOtherWord parameters
++ DcmElement *vldata = &voiLUTData;
++ vldata->operator=(*(DcmElement *)(stack.top()));
+ }
+ } else result=EC_TagNotFound;
+ }
+diff --git a/dcmpstat/libsrc/dvpstat.cc b/dcmpstat/libsrc/dvpstat.cc
+index ce2f5ad5ff..4bfe8f9cbd 100644
+--- a/dcmpstat/libsrc/dvpstat.cc
++++ b/dcmpstat/libsrc/dvpstat.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1998-2021, OFFIS e.V.
++ * Copyright (C) 1998-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -578,14 +578,14 @@ OFCondition DVPresentationState::attachImage(DcmDataset *dataset, OFBool transfe
+ currentImageSelectedFrame = 1; // default: first frame
+
+ // get Modality
+- if (EC_Normal == dataset->search(DCM_Modality, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dataset->search(DCM_Modality, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_CS))
+ {
+ currentImageModality = *((DcmCodeString *)(stack.top()));
+ }
+ stack.clear();
+
+ // determine default Presentation LUT Shape
+- if (EC_Normal == dataset->search(DCM_PhotometricInterpretation, stack, ESM_fromHere, OFFalse))
++ if (EC_Normal == dataset->search(DCM_PhotometricInterpretation, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_CS))
+ {
+ DcmCodeString *photometricInterpretation = (DcmCodeString *)(stack.top());
+ if (photometricInterpretation->getVM() == 1)
+@@ -598,12 +598,12 @@ OFCondition DVPresentationState::attachImage(DcmDataset *dataset, OFBool transfe
+ stack.clear();
+
+ // get SOP class UID and SOP instance UID.
+- if ((EC_Normal == result)&&(EC_Normal == dataset->search(DCM_SOPClassUID, stack, ESM_fromHere, OFFalse)))
++ if ((EC_Normal == result)&&(EC_Normal == dataset->search(DCM_SOPClassUID, stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_UI))
+ {
+ result = ((DcmUniqueIdentifier *)(stack.top()))->getString(currentImageSOPClassUID);
+ }
+ stack.clear();
+- if ((EC_Normal == result)&&(EC_Normal == dataset->search(DCM_SOPInstanceUID, stack, ESM_fromHere, OFFalse)))
++ if ((EC_Normal == result)&&(EC_Normal == dataset->search(DCM_SOPInstanceUID, stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_UI))
+ {
+ result = ((DcmUniqueIdentifier *)(stack.top()))->getString(currentImageSOPInstanceUID);
+ }
+@@ -1124,40 +1124,36 @@ OFCondition DVPresentationState::setGammaVOILUT(double gammaValue, DVPSObjectApp
+ numEntries16 = (Uint16)numberOfEntries;
+
+ /* LUT Descriptor */
+- DcmElement *lutDescriptor = NULL;
+- if (firstMapped < 0)
++ DcmUnsignedShort *lutDescriptor = new DcmUnsignedShort(DcmTag(DCM_LUTDescriptor, EVR_US));
++ if (lutDescriptor == NULL) status = EC_MemoryExhausted;
++ else
+ {
+- // LUT Descriptor is SS
+- lutDescriptor = new DcmSignedShort(DcmTag(DCM_LUTDescriptor, EVR_SS));
+- if (lutDescriptor != NULL)
++ if (firstMapped < 0)
+ {
+- status = lutDescriptor->putSint16((Sint16)numEntries16, 0);
+- if (EC_Normal == status)
+- status = lutDescriptor->putSint16((Sint16)firstMapped, 1);
+- if (EC_Normal == status)
+- status = lutDescriptor->putSint16((Sint16)numberOfBits, 2);
+- } else
+- status = EC_MemoryExhausted;
+- } else {
+- // LUT Descriptor is US
+- lutDescriptor = new DcmUnsignedShort(DcmTag(DCM_LUTDescriptor, EVR_US));
+- if (lutDescriptor != NULL)
+- {
+- status = lutDescriptor->putUint16(numEntries16, 0);
+- if (EC_Normal == status)
+- status = lutDescriptor->putUint16((Uint16)firstMapped, 1);
+- if (EC_Normal == status)
+- status = lutDescriptor->putUint16((Uint16)numberOfBits, 2);
+- } else
+- status = EC_MemoryExhausted;
++ // LUT Descriptor is SS
++ DcmSignedShort ldesc(DcmTag(DCM_LUTDescriptor, EVR_SS));
++ status = ldesc.putSint16((Sint16)numEntries16, 0);
++ if (EC_Normal == status) status = ldesc.putSint16((Sint16)firstMapped, 1);
++ if (EC_Normal == status) status = ldesc.putSint16((Sint16)numberOfBits, 2);
++ if (EC_Normal == status)
++ {
++ // copy content of SS element into DcmUnsignedShort using DcmElement::operator=
++ DcmElement *ld = lutDescriptor;
++ ld->operator=(ldesc);
++ }
++ } else {
++ // LUT Descriptor is US
++ status = lutDescriptor->putUint16(numEntries16, 0);
++ if (EC_Normal == status) status = lutDescriptor->putUint16((Uint16)firstMapped, 1);
++ if (EC_Normal == status) status = lutDescriptor->putUint16((Uint16)numberOfBits, 2);
++ }
+ }
+
+ /* LUT Data */
+- DcmElement *lutData = NULL;
++ DcmUnsignedShort *lutData = NULL;
+ if (status == EC_Normal)
+ {
+- // LUT Data as OW, because of max size = 64K
+- lutData = new DcmOtherByteOtherWord(DcmTag(DCM_LUTData, EVR_OW));
++ lutData = new DcmUnsignedShort(DcmTag(DCM_LUTData, EVR_US));
+ if (lutData != NULL)
+ status = lutData->putUint16Array(data, numberOfEntries);
+ else
+@@ -1186,15 +1182,14 @@ OFCondition DVPresentationState::setGammaVOILUT(double gammaValue, DVPSObjectApp
+ if (status == EC_Normal)
+ {
+ if ((lutDescriptor != NULL) && (lutData != NULL) && (lutExplanation != NULL))
+- status = setVOILUT(*(DcmUnsignedShort *)lutDescriptor, *(DcmUnsignedShort *)lutData, *lutExplanation, applicability);
++ status = setVOILUT(*lutDescriptor, *lutData, *lutExplanation, applicability);
+ }
+
+ /* delete temporary dcmtk structures */
+ delete lutDescriptor;
+ delete lutData;
+ delete lutExplanation;
+- } else
+- status = EC_MemoryExhausted;
++ } else status = EC_MemoryExhausted;
+ delete[] data;
+ }
+ return status;
+diff --git a/dcmpstat/libsrc/dvpsvl.cc b/dcmpstat/libsrc/dvpsvl.cc
+index b10b83f20d..fdba0a0e06 100644
+--- a/dcmpstat/libsrc/dvpsvl.cc
++++ b/dcmpstat/libsrc/dvpsvl.cc
+@@ -59,9 +59,24 @@ OFCondition DVPSVOILUT::read(DcmItem &dset)
+ OFCondition result = EC_Normal;
+ DcmStack stack;
+
+- READ_FROM_DATASET(DcmUnsignedShort, EVR_US, voiLUTDescriptor)
++ // LUTDescriptor can be US or SS
++ if ((EC_Normal == dset.search((DcmTagKey &)voiLUTDescriptor.getTag(),
++ stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_SS))
++ {
++ // We explicitly use DcmElement::operator=(), which works for US and SS
++ DcmElement *vLUTDescriptor = &voiLUTDescriptor;
++ vLUTDescriptor->operator=(* OFstatic_cast(DcmElement *, stack.top()));
++ }
++
+ READ_FROM_DATASET(DcmLongString, EVR_LO, voiLUTExplanation)
+- READ_FROM_DATASET(DcmUnsignedShort, EVR_US, voiLUTData)
++
++ stack.clear();
++ if ((EC_Normal == dset.search((DcmTagKey &)voiLUTData.getTag(), stack, ESM_fromHere, OFFalse)) && (stack.top()->ident() == EVR_US || stack.top()->ident() == EVR_OW))
++ {
++ // we deliberately call DcmElement::operator=() here, which will work for both DcmUnsignedShort and DcmOtherByteOtherWord parameters
++ DcmElement *vldata = &voiLUTData;
++ vldata->operator=(*(DcmElement *)(stack.top()));
++ }
+
+ if (EC_Normal == result)
+ {
=====================================
debian/patches/0003-Fixed-wrong-error-handling-previous-commit.patch
=====================================
@@ -0,0 +1,82 @@
+From 7d54f8efec995e5601d089fa17b0625c2b41af23 Mon Sep 17 00:00:00 2001
+From: Joerg Riesmeier <dicom at jriesmeier.com>
+Date: Mon, 22 Apr 2024 12:11:11 +0200
+Subject: [PATCH] Fixed wrong error handling (previous commit).
+
+Fixed wrong error handling introduced with the previous commit.
+---
+ dcmrt/libsrc/drttypes.cc | 6 +++---
+ dcmsr/libsrc/dsrtypes.cc | 32 ++++++++++++++++++++------------
+ 2 files changed, 23 insertions(+), 15 deletions(-)
+
+diff --git a/dcmrt/libsrc/drttypes.cc b/dcmrt/libsrc/drttypes.cc
+index 77ff1674c..097ab9727 100644
+--- a/dcmrt/libsrc/drttypes.cc
++++ b/dcmrt/libsrc/drttypes.cc
+@@ -210,11 +210,11 @@ OFCondition DRTTypes::getAndCheckStringValueFromDataset(DcmItem &dataset,
+ {
+ DcmStack stack;
+ OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+- if (result.good() && stack.top()->isElement())
++ if (result.good())
+ {
+- DcmElement *element = OFstatic_cast(DcmElement *, stack.top());
+- if (element != NULL)
++ if (stack.top()->isElement())
+ {
++ DcmElement *element = OFstatic_cast(DcmElement *, stack.top());
+ if (checkElementValue(*element, vm, type, result, moduleName))
+ result = element->getOFString(stringValue, 0);
+ else
+diff --git a/dcmsr/libsrc/dsrtypes.cc b/dcmsr/libsrc/dsrtypes.cc
+index a9d621859..166bfabff 100644
+--- a/dcmsr/libsrc/dsrtypes.cc
++++ b/dcmsr/libsrc/dsrtypes.cc
+@@ -1178,13 +1178,17 @@ OFCondition DSRTypes::getAndCheckElementFromDataset(DcmItem &dataset,
+ DcmStack stack;
+ const DcmTagKey tagKey = delem.getTag();
+ OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+- if (result.good() && stack.top()->isElement())
++ if (result.good())
+ {
+- /* copy object from search stack */
+- result = delem.copyFrom(*stack.top());
+- /* we need a reference to the original element in order to determine the SpecificCharacterSet */
+- if (!checkElementValue(OFstatic_cast(DcmElement *, stack.top()), tagKey, vm, type, result, moduleName, acceptViolation))
+- result = SR_EC_InvalidValue;
++ if (stack.top()->isElement())
++ {
++ /* copy object from search stack */
++ result = delem.copyFrom(*stack.top());
++ /* we need a reference to the original element in order to determine the SpecificCharacterSet */
++ if (!checkElementValue(OFstatic_cast(DcmElement *, stack.top()), tagKey, vm, type, result, moduleName, acceptViolation))
++ result = SR_EC_InvalidValue;
++ } else
++ result = EC_CorruptedData;
+ }
+ /* the element could not be found in the dataset */
+ else if (!checkElementValue(delem, vm, type, result, moduleName, acceptViolation))
+@@ -1203,13 +1207,17 @@ OFCondition DSRTypes::getAndCheckStringValueFromDataset(DcmItem &dataset,
+ {
+ DcmStack stack;
+ OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
+- if (result.good() && stack.top()->isElement())
++ if (result.good())
+ {
+- DcmElement *delem = OFstatic_cast(DcmElement *, stack.top());
+- /* we need a reference to the original element in order to determine the SpecificCharacterSet */
+- if (!checkElementValue(delem, tagKey, vm, type, result, moduleName, acceptViolation))
+- result = SR_EC_InvalidValue;
+- delem->getOFString(stringValue, 0);
++ if (stack.top()->isElement())
++ {
++ DcmElement *delem = OFstatic_cast(DcmElement *, stack.top());
++ /* we need a reference to the original element in order to determine the SpecificCharacterSet */
++ if (!checkElementValue(delem, tagKey, vm, type, result, moduleName, acceptViolation))
++ result = SR_EC_InvalidValue;
++ delem->getOFString(stringValue, 0);
++ } else
++ result = EC_CorruptedData;
+ } else {
+ if ((type == "1") || (type == "2"))
+ {
=====================================
debian/patches/0004-Fixed-two-segmentation-faults.patch
=====================================
@@ -0,0 +1,95 @@
+From c78e434c0c5f9d932874f0b17a8b4ce305ca01f5 Mon Sep 17 00:00:00 2001
+From: Marco Eichelberg <dicom at offis.de>
+Date: Wed, 13 Mar 2024 17:15:58 +0100
+Subject: [PATCH] Fixed two segmentation faults.
+
+Fixed two segmentations faults that could occur while processing an
+invalid incoming DIMSE message due to insufficient error handling
+causing a de-referenced NULL pointer.
+
+Thanks to Nils Bars <nils.bars at rub.de> for the bug report and sample files.
+
+This closes DCMTK issue #1114.
+---
+ dcmdata/libsrc/dcelem.cc | 9 ++++++++-
+ dcmnet/libsrc/dimcmd.cc | 33 ++++++++++++++++++---------------
+ 2 files changed, 26 insertions(+), 16 deletions(-)
+
+diff --git a/dcmdata/libsrc/dcelem.cc b/dcmdata/libsrc/dcelem.cc
+index 1524904be..3b9cc2bf7 100644
+--- a/dcmdata/libsrc/dcelem.cc
++++ b/dcmdata/libsrc/dcelem.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1994-2023, OFFIS e.V.
++ * Copyright (C) 1994-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -717,6 +717,13 @@ OFCondition DcmElement::loadValue(DcmInputStream *inStream)
+ if (isStreamNew)
+ delete readStream;
+ }
++ else
++ {
++ errorFlag = EC_InvalidStream; // incomplete dataset read from stream
++ DCMDATA_ERROR("DcmElement: " << getTagName() << " " << getTag()
++ << " larger (" << getLengthField() << ") than remaining bytes ("
++ << getTransferredBytes() << ") in file, premature end of stream");
++ }
+ }
+ /* return result value */
+ return errorFlag;
+diff --git a/dcmnet/libsrc/dimcmd.cc b/dcmnet/libsrc/dimcmd.cc
+index 6dca39546..ffd225f4b 100644
+--- a/dcmnet/libsrc/dimcmd.cc
++++ b/dcmnet/libsrc/dimcmd.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 1994-2022, OFFIS e.V.
++ * Copyright (C) 1994-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were partly developed by
+@@ -205,22 +205,25 @@ getString(DcmDataset *obj, DcmTagKey t, char *s, int maxlen, OFBool *spacePadded
+ return parseErrorWithMsg("dimcmd:getString: string too small", t);
+ } else {
+ ec = elem->getString(aString);
+- strncpy(s, aString, maxlen);
+- if (spacePadded)
++ if (ec.good())
+ {
+- /* before we remove leading and tailing spaces we want to know
+- * whether the string is actually space padded. Required to communicate
+- * with dumb peers which send space padded UIDs and fail if they
+- * receive correct UIDs back.
+- *
+- * This test can only detect space padded strings if
+- * dcmEnableAutomaticInputDataCorrection is false; otherwise the padding
+- * has already been removed by dcmdata at this stage.
+- */
+- size_t s_len = strlen(s);
+- if ((s_len > 0)&&(s[s_len-1] == ' ')) *spacePadded = OFTrue; else *spacePadded = OFFalse;
++ strncpy(s, aString, maxlen);
++ if (spacePadded)
++ {
++ /* before we remove leading and tailing spaces we want to know
++ * whether the string is actually space padded. Required to communicate
++ * with dumb peers which send space padded UIDs and fail if they
++ * receive correct UIDs back.
++ *
++ * This test can only detect space padded strings if
++ * dcmEnableAutomaticInputDataCorrection is false; otherwise the padding
++ * has already been removed by dcmdata at this stage.
++ */
++ size_t s_len = strlen(s);
++ if ((s_len > 0)&&(s[s_len-1] == ' ')) *spacePadded = OFTrue; else *spacePadded = OFFalse;
++ }
++ DU_stripLeadingAndTrailingSpaces(s);
+ }
+- DU_stripLeadingAndTrailingSpaces(s);
+ }
+ }
+ return (ec.good())? ec : DIMSE_PARSEFAILED;
=====================================
debian/patches/0005-Fixed-DcmDecimalString-unit-tests.patch
=====================================
@@ -0,0 +1,66 @@
+From 66c317feae446deda1a389226aa24c95a0eeac4c Mon Sep 17 00:00:00 2001
+From: Marco Eichelberg <dicom at offis.de>
+Date: Wed, 13 Mar 2024 23:03:40 +0100
+Subject: [PATCH] Fixed DcmDecimalString unit tests.
+
+---
+ dcmdata/tests/tvrds.cc | 12 ++++++------
+ 1 file changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/dcmdata/tests/tvrds.cc b/dcmdata/tests/tvrds.cc
+index a9132a341..0e929304d 100644
+--- a/dcmdata/tests/tvrds.cc
++++ b/dcmdata/tests/tvrds.cc
+@@ -1,6 +1,6 @@
+ /*
+ *
+- * Copyright (C) 2011-2020, OFFIS e.V.
++ * Copyright (C) 2011-2024, OFFIS e.V.
+ * All rights reserved. See COPYRIGHT file for details.
+ *
+ * This software and supporting documentation were developed by
+@@ -30,7 +30,7 @@
+
+ OFTEST(dcmdata_decimalString_1)
+ {
+- DcmDecimalString decStr(DCM_ContourData, EVR_DS);
++ DcmDecimalString decStr(DCM_ContourData);
+ OFVector<Float64> doubleVals;
+ OFCHECK(decStr.putString("1\\2.0\\3.5\\-4.99\\+500.005\\6.66E-01").good());
+ OFCHECK(decStr.getFloat64Vector(doubleVals).good());
+@@ -45,7 +45,7 @@ OFTEST(dcmdata_decimalString_1)
+
+ OFTEST(dcmdata_decimalString_2)
+ {
+- DcmDecimalString decStr(DCM_ContourData, EVR_DS);
++ DcmDecimalString decStr(DCM_ContourData);
+ OFVector<Float64> doubleVals;
+ /* insert a NULL byte into the string */
+ OFCHECK(decStr.putString("1\\2.0\\3.5\\-4.99\0\\+500.005\\6.66E-01", 34).good());
+@@ -61,7 +61,7 @@ OFTEST(dcmdata_decimalString_2)
+
+ OFTEST(dcmdata_decimalString_3)
+ {
+- DcmDecimalString decStr(DCM_ContourData, EVR_DS);
++ DcmDecimalString decStr(DCM_ContourData);
+ OFVector<Float64> doubleVals;
+ /* insert a NULL byte into the string */
+ OFCHECK(decStr.putOFStringArray(OFString("1\\2.0\\3.5\\-4.99\0\\+500.005\\6.66E-01", 34)).good());
+@@ -77,7 +77,7 @@ OFTEST(dcmdata_decimalString_3)
+
+ OFTEST(dcmdata_decimalString_4)
+ {
+- DcmDecimalString decStr(DCM_ContourData, EVR_DS);
++ DcmDecimalString decStr(DCM_ContourData);
+ OFVector<Float64> doubleVals;
+ OFCHECK(decStr.putString("1\\2.0\\3.5\\-4.99\\+500.005\\6.66E-01\\").good());
+ OFCHECK_EQUAL(decStr.getVM(), 7);
+@@ -96,7 +96,7 @@ OFTEST(dcmdata_decimalString_putFloat64)
+ {
+ // Test insertion in the beginning
+ OFString testStr;
+- DcmDecimalString decStr(DCM_ContourData, EVR_DS);
++ DcmDecimalString decStr(DCM_ContourData);
+ OFCHECK(decStr.putFloat64(0, 0).good());
+ decStr.getOFStringArray(testStr);
+ OFCHECK(testStr == "0");
=====================================
debian/patches/01_dcmtk_3.6.0-1.patch
=====================================
@@ -2,7 +2,7 @@ Author: Jürgen Salk <jsa at debian.org>
Description: The original maintainer Jürgen Salk applied
a set of patches to the original code. This file contains
changes to C++ code
-Forwarded: no
+Forwarded: not-needed
--- a/dcmqrdb/etc/dcmqrscp.cfg
+++ b/dcmqrdb/etc/dcmqrscp.cfg
=====================================
debian/patches/03_datadic_install.patch
=====================================
@@ -1,6 +1,6 @@
Description: Install dict to versioned dir
Bug-Debian: https://bugs.debian.org/709123
-Forwarded: no
+Forwarded: not-needed
Author: Mathieu Malaterre <malat at debian.org>
--- a/CMake/GenerateDCMTKConfigure.cmake
+++ b/CMake/GenerateDCMTKConfigure.cmake
=====================================
debian/patches/07_dont_export_all_executables.patch
=====================================
@@ -6,6 +6,7 @@ Description: Don't add executables to cmake exports
to configure the according package.
Bug-Debian: https://bugs.debian.org/803304
Author: Gert Wollny <gw.fossdev at gmail.com>
+Forwarded: not-needed
Index: dcmtk/CMake/dcmtkMacros.cmake
===================================================================
--- dcmtk.orig/CMake/dcmtkMacros.cmake
=====================================
debian/patches/fake_version.patch deleted
=====================================
@@ -1,5 +0,0 @@
-Description: Fake a release
-Author: Mathieu Malaterre <malat at debian.org>
-Forwarded: not-needed
-Last-Update: 2022-10-18
-
=====================================
debian/patches/series
=====================================
@@ -11,3 +11,8 @@
#f06a867513524664a1b03dfcf812d8b60fdd02cc.patch
remove_version.patch
da5370947226783ce3548bf1e5b7112fac70de46.patch
+0001-Fixed-unchecked-typecasts-of-DcmItem-search-results.patch
+0002-Fixed-unchecked-typecasts-and-fixed-LUT-handling.patch
+0003-Fixed-wrong-error-handling-previous-commit.patch
+0004-Fixed-two-segmentation-faults.patch
+0005-Fixed-DcmDecimalString-unit-tests.patch
=====================================
debian/rules
=====================================
@@ -4,6 +4,7 @@
# export DEB_BUILD_MAINT_OPTIONS = hardening=+pie
ifeq ($(DEB_TARGET_ARCH),armel)
# https://lists.debian.org/debian-arm/2024/01/msg00031.html
+ # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1060104
export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-stackclash optimize=+lto
else
export DEB_BUILD_MAINT_OPTIONS = hardening=+all optimize=+lto
=====================================
debian/tests/run-unit-test
=====================================
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
set -e
pkg=dcmtk
@@ -13,74 +13,74 @@ if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
fi
cp -a /usr/lib/python3/dist-packages/pydicom/data/test_files/CT_small.dcm "${AUTOPKGTEST_TMP}"
-cp -a ${CUR_DIR}/dcmdata/data/dicom.dic "${AUTOPKGTEST_TMP}"
+cp -a /usr/share/libdcmtk17/dicom.dic "${AUTOPKGTEST_TMP}"
export DCMDICTPATH=${AUTOPKGTEST_TMP}/dicom.dic
cd "${AUTOPKGTEST_TMP}"
-echo -e "15e7e2a11cdeabac32e1134674beda6b CT_small.dcm" >> checksums
+echo "15e7e2a11cdeabac32e1134674beda6b CT_small.dcm" >> checksums
-echo -e "Running Tests"
+echo "Running Tests"
-echo -e "Test 1"
+echo "Test 1"
dcm2json CT_small.dcm dcm2json.json
-echo -e "Test 2"
+echo "Test 2"
dcm2xml CT_small.dcm dcm2xml.xml
-echo -e "Test 3"
+echo "Test 3"
dcmconv --convert-to-latin1 CT_small.dcm dcmconv.out
-echo -e "Test 4"
+echo "Test 4"
dcmcrle CT_small.dcm dcmcrle.out
-echo -e "Test 5"
+echo "Test 5"
dcmdrle dcmcrle.out dcmdrle.out
-echo -e "Test 6"
+echo "Test 6"
dcmdump CT_small.dcm > dcmdump.out
-echo -e "Test 7"
+echo "Test 7"
dump2dcm dcmdump.out dump2dcm.dcm
-echo -e "Test 8"
+echo "Test 8"
dcmftest CT_small.dcm
-echo -e "Test 9"
+echo "Test 9"
dcmodify -e "(0008,0031)" CT_small.dcm
-echo -e "Test 10"
+echo "Test 10"
dcm2pnm +Rtd CT_small.dcm dcm2pnm.png
-echo -e "Test 11"
+echo "Test 11"
dcmscale +Sxf 2.0 CT_small.dcm dcmscale.out
-echo -e "Test 12"
+echo "Test 12"
dcmcjpls CT_small.dcm dcmcjpls.out
-echo -e "Test 13"
+echo "Test 13"
dcmdjpls dcmcjpls.out dcmdjpls.out
-echo -e "Test 14"
+echo "Test 14"
dcml2pnm CT_small.dcm dcml2pnm.png
-echo -e "Test 15"
+echo "Test 15"
cat <<EOT >> crv.txt
256.451947 1.000000
@@ -92,23 +92,23 @@ EOT
dcmmkcrv CT_small.dcm crv.txt dcmmkcrv.out
-echo -e "Test 16"
+echo "Test 16"
dcmmklut dcmmklut.out
-echo -e "Test 17"
+echo "Test 17"
dcmp2pgm CT_small.dcm dcmp2pgm.out
-echo -e "Test 18"
+echo "Test 18"
dcmpsmk CT_small.dcm dcmpsmk.out
-echo -e "Test 19"
+echo "Test 19"
mkdir dcmqridx
dcmqridx dcmqridx/ CT_small.dcm
-echo -e "Test 20"
+echo "Test 20"
dcmsign -q CT_small.dcm
if [ -f dcmqridx/index.dat ] && \
@@ -130,7 +130,7 @@ if [ -f dcmqridx/index.dat ] && \
[ -f dcmp2pgm.out ] && \
md5sum --check checksums; then
- echo -e "PASS"
+ echo "PASS"
else
echo "FAIL"
View it on GitLab: https://salsa.debian.org/med-team/dcmtk/-/compare/46d5e619b64767b797328d050d90be58a7e4c493...207c46c2df2a9327e5a3d78028fb6f1d034f0371
--
This project does not include diff previews in email notifications.
View it on GitLab: https://salsa.debian.org/med-team/dcmtk/-/compare/46d5e619b64767b797328d050d90be58a7e4c493...207c46c2df2a9327e5a3d78028fb6f1d034f0371
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20240624/10e88f06/attachment-0001.htm>
More information about the debian-med-commit
mailing list