From 790c5880157be23f2fddd6cd35c9ea0cb8ea0b3a Mon Sep 17 00:00:00 2001 From: Valen Torassa Date: Tue, 10 Nov 2026 12:42:37 -0300 Subject: [PATCH] debian: invesalius and pydicom updates, gdcm trixie-pu filed invesalius: patch for CVE-2024-44825 (Debian #1136204), trixie debdiff 3.1.99998-7+deb13u1 and a draft reply to the bug with test results for this patch and for the one Christoph Jahnke proposed there. pydicom: upstream's 2.4.5 fix for CVE-2026-32711 (Debian #1131492), trixie debdiff 2.4.3-2+deb13u1 and drafts of the mail to debian-med and of the trixie-pu request. gdcm: the trixie-pu request is recorded as filed (#1153126) with the text as sent, and the bookworm debdiff sent to debian-med on 2026-11-05 is added. README: new section with the state of the Debian updates. --- README.md | 48 +- .../gdcm_3.0.21-1+deb12u1_bookworm.debdiff | 908 ++++++++++++++++++ gdcm/debian/trixie-pu-request.md | 23 +- invesalius/CVE-2024-44825.patch | 60 ++ invesalius/debian/bug-1136204-reply.md | 81 ++ ...esalius_3.1.99998-7+deb13u1_trixie.debdiff | 120 +++ pydicom/CVE-2026-32711.patch | 560 +++++++++++ pydicom/debian/email-debian-med.md | 59 ++ .../pydicom_2.4.3-2+deb13u1_trixie.debdiff | 601 ++++++++++++ pydicom/debian/trixie-pu-request.md | 78 ++ 10 files changed, 2521 insertions(+), 17 deletions(-) create mode 100644 gdcm/debian/gdcm_3.0.21-1+deb12u1_bookworm.debdiff create mode 100644 invesalius/CVE-2024-44825.patch create mode 100644 invesalius/debian/bug-1136204-reply.md create mode 100644 invesalius/debian/invesalius_3.1.99998-7+deb13u1_trixie.debdiff create mode 100644 pydicom/CVE-2026-32711.patch create mode 100644 pydicom/debian/email-debian-med.md create mode 100644 pydicom/debian/pydicom_2.4.3-2+deb13u1_trixie.debdiff create mode 100644 pydicom/debian/trixie-pu-request.md diff --git a/README.md b/README.md index 007ad38..1ded363 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,13 @@ software where a CVE is public, an upstream fix exists, but nothing has landed i channel most people actually run. Each fix here is **DEP-3 formatted** and ready to drop into `debian/patches/`, with the -provenance (upstream commit, CVE, bug links) baked into the patch header. Today the -focus is **Ubuntu `universe`** CVEs, but the layout is distro-agnostic - anything with a -public CVE and an upstream fix is fair game. +provenance (upstream commit, CVE, bug links) baked into the patch header. The focus is +**Ubuntu `universe`** CVEs and, since November 2026, **Debian stable** updates. The +layout is distro-agnostic - anything with a public CVE and an upstream fix is fair game. | | | |---|---| -| **Scope** | Open-source security patches (currently Ubuntu universe) | +| **Scope** | Open-source security patches (Ubuntu universe and Debian stable) | | **Format** | DEP-3 patches, ready for `debian/patches/` | | **Status** | Tracked in [`fixes.yaml`](fixes.yaml) | | **Contributing** | See [`CONTRIBUTING.md`](CONTRIBUTING.md) | @@ -113,6 +113,39 @@ formatted so a maintainer can pick them up with zero rework. --- +## Debian stable updates + +Since November 2026 the same method is applied to Debian itself, for packages of the +[Debian Med](https://www.debian.org/devel/debian-med/) team that read medical image files +and still have open CVEs in the stable release. These updates go through the package +maintainers and a stable point release (`trixie-pu`), not through an SRU, so they are not +part of `fixes.yaml` or `tools/submit-sru.sh`. + +State on 2026-11-10. **None of these is in the Debian archive yet.** + +| Package | Target | Issue | Where | State | +|---|---|---|---|---| +| `gdcm` | unstable | Regression of the CVE-2025-53618 / CVE-2025-53619 patch | [#1152837](https://bugs.debian.org/1152837) | Reported with a patch; open | +| `gdcm` | trixie (13) | CVE-2025-11266, CVE-2025-48429, CVE-2025-52582, CVE-2025-53618, CVE-2025-53619, CVE-2026-3650 | [#1153126](https://bugs.debian.org/1153126) | `trixie-pu` request filed with the [debdiff](gdcm/debian/gdcm_3.0.24-5+deb13u1_trixie.debdiff); agreed with the team, waiting for the release team | +| `gdcm` | bookworm (12, LTS) | The same six CVEs | debian-med list | [Debdiff](gdcm/debian/gdcm_3.0.21-1+deb12u1_bookworm.debdiff) sent on 2026-11-05; a Debian developer is reviewing it | +| `invesalius` | unstable, then trixie (13) | CVE-2024-44825, plus CVE-2024-42845 in trixie | [#1136204](https://bugs.debian.org/1136204) | [Patch](invesalius/CVE-2024-44825.patch) and [trixie debdiff](invesalius/debian/invesalius_3.1.99998-7+deb13u1_trixie.debdiff) built and tested; not submitted yet | +| `pydicom` | trixie (13) | CVE-2026-32711 | [#1131492](https://bugs.debian.org/1131492) | [Patch](pydicom/CVE-2026-32711.patch) and [debdiff](pydicom/debian/pydicom_2.4.3-2+deb13u1_trixie.debdiff) built and tested; not submitted yet | + +Each of these package folders has a `debian/` subfolder with the debdiff and the text of +what was sent or is going to be sent: the mail to the team, the bug report or reply, and +the `trixie-pu` request. A draft says so in its first line. + +How an update is prepared: + +1. Take the CVEs that the [Debian security tracker](https://security-tracker.debian.org/tracker/) + lists as open in stable and that are fixed in unstable or upstream. +2. Backport the patch with a DEP-3 header. +3. Build in a clean container of the target release. +4. Compare the old and the new package, on crafted input and on ordinary files. +5. Agree the change with the maintainers before asking the release team. + +--- + ## Status review - 2026-09-29 Read from the live trackers on 2026-09-29. **No fix has landed in a standard Ubuntu pocket @@ -197,11 +230,14 @@ tools/ submit-sru.sh → build source-only SRU uploads for every fix (Ubuntu only) libsoup3/ → CVE-2025-11021 / CVE-2025-4945 libyaml-syck-perl/ → CVE-2025-11683 -gdcm/ → CVE-2025-11266 +gdcm/ → CVE-2025-11266; debian/ has the trixie and bookworm updates +invesalius/ → CVE-2024-44825 (Debian only) +pydicom/ → CVE-2026-32711 (Debian only) ``` Each package folder contains the `.patch` file, a ready-to-file `bug-report.md`, and any -packaging diffs (`changelog.diff`, `*.debdiff`). +packaging diffs (`changelog.diff`, `*.debdiff`). The Debian-only folders have no +`bug-report.md`; their texts are in `debian/`. ### Add a fix diff --git a/gdcm/debian/gdcm_3.0.21-1+deb12u1_bookworm.debdiff b/gdcm/debian/gdcm_3.0.21-1+deb12u1_bookworm.debdiff new file mode 100644 index 0000000..12fef24 --- /dev/null +++ b/gdcm/debian/gdcm_3.0.21-1+deb12u1_bookworm.debdiff @@ -0,0 +1,908 @@ +diff -Nru gdcm-3.0.21/debian/changelog gdcm-3.0.21/debian/changelog +--- gdcm-3.0.21/debian/changelog 2023-01-29 14:21:24.000000000 +0000 ++++ gdcm-3.0.21/debian/changelog 2026-11-05 20:35:37.000000000 +0000 +@@ -1,3 +1,36 @@ ++gdcm (3.0.21-1+deb12u1) bookworm-security; urgency=medium ++ ++ * Non-maintainer upload by the LTS Team. ++ ++ [ Étienne Mollier ] ++ * CVE-2024-*.patch: new: fix multiple security issues. ++ This patch set addresses CVE-2024-22373, CVE-2024-22391 and ++ CVE-2024-25569. (Closes: #1070387) ++ ++ [ Emmanuel Arias ] ++ * CVE-2025-11266.patch: Avoid out-of-bounds vulnerability. The issue ++ was triggered during parsing of a malformed DICOM file containing ++ encapsulated PixelData fragments. This vulnerability leads to a ++ segmentation fault caused by an out-of-bounds memory access due to ++ unsigned integer underflow in buffer indexing (Closes: #1122862). ++ ++ [ Valentín Torassa ] ++ * CVE-2025-52582.patch: Prevent overlay extraction in case of malformed ++ overlay or image information (Closes: #1123576). ++ * CVE-2025-53618_CVE-2025-53619.patch: Add a frame size check to ensure ++ that the provided data corresponds to the buffer size. Fixes ++ CVE-2025-53618 and CVE-2025-53619 (Closes: #1123587). ++ * CVE-2025-48429.patch: Refactor the RLE header to ensure it conforms to ++ the DICOM standard (Closes: #1123589). ++ * CVE-2026-3650.patch: Reject Value Length exceeding stream size ++ (Closes: #1132042). ++ * CVE-2025-53618_CVE-2025-53619-regression.patch: Accept frames with ++ one byte of odd-length padding in the JPEG encoder, fixing a ++ regression from the CVE-2025-53618/CVE-2025-53619 fix (upstream ++ commit 9ced0f9). ++ ++ -- Valentín Torassa Thu, 05 Nov 2026 17:35:37 -0300 ++ + gdcm (3.0.21-1) unstable; urgency=medium + + * Team upload. +diff -Nru gdcm-3.0.21/debian/patches/CVE-2024-22373.patch gdcm-3.0.21/debian/patches/CVE-2024-22373.patch +--- gdcm-3.0.21/debian/patches/CVE-2024-22373.patch 1970-01-01 00:00:00.000000000 +0000 ++++ gdcm-3.0.21/debian/patches/CVE-2024-22373.patch 2026-11-05 20:35:37.000000000 +0000 +@@ -0,0 +1,38 @@ ++commit 371c2d937e37b08a46eeb0628c553ce4608a45df ++Author: Mathieu Malaterre ++Date: Wed Feb 21 02:18:35 2024 -0800 ++ ++ Remove symptoms from TALOS-2024-1935 ++ ++diff --git a/Source/MediaStorageAndFileFormat/gdcmImageChangeTransferSyntax.cxx b/Source/MediaStorageAndFileFormat/gdcmImageChangeTransferSyntax.cxx ++index fcb61e611..9457c5e9b 100644 ++--- a/Source/MediaStorageAndFileFormat/gdcmImageChangeTransferSyntax.cxx +++++ b/Source/MediaStorageAndFileFormat/gdcmImageChangeTransferSyntax.cxx ++@@ -421,6 +421,7 @@ bool ImageChangeTransferSyntax::Change() ++ if( !b ) ++ { ++ gdcmErrorMacro( "Error in getting buffer from input image." ); +++ delete bv0; ++ return false; ++ } ++ pixeldata.SetValue( *bv0 ); ++diff --git a/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx b/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx ++index 10ac23cca..430a24a87 100644 ++--- a/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx +++++ b/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx ++@@ -826,8 +826,13 @@ std::pair JPEG2000Codec::DecodeByStreamsCommon(char *dummy_buffe ++ ++ // ELSCINT1_JP2vsJ2K.dcm ++ // -> prec = 12, bpp = 0, sgnd = 0 ++- //assert( wr == Dimensions[0] ); ++- //assert( hr == Dimensions[1] ); +++ if( wr != Dimensions[0] || hr != Dimensions[1] ) { +++ gdcmErrorMacro("Invalid dimension"); +++ delete[] raw; +++ opj_destroy_codec(dinfo); +++ opj_image_destroy(image); +++ return std::pair(nullptr,0); +++ } ++ if( comp->sgnd != PF.GetPixelRepresentation() ) ++ { ++ PF.SetPixelRepresentation( (uint16_t)comp->sgnd ); +diff -Nru gdcm-3.0.21/debian/patches/CVE-2024-22391.patch gdcm-3.0.21/debian/patches/CVE-2024-22391.patch +--- gdcm-3.0.21/debian/patches/CVE-2024-22391.patch 1970-01-01 00:00:00.000000000 +0000 ++++ gdcm-3.0.21/debian/patches/CVE-2024-22391.patch 2026-11-05 20:35:37.000000000 +0000 +@@ -0,0 +1,63 @@ ++commit 21a793095ab3aecb794c56439873e5b181ea9d91 ++Author: Mathieu Malaterre ++Date: Wed Feb 21 02:00:38 2024 -0800 ++ ++ Remove symptoms of TALOS-2024-1924 ++ ++diff --git a/Source/DataStructureAndEncodingDefinition/gdcmElement.h b/Source/DataStructureAndEncodingDefinition/gdcmElement.h ++index b49b093dc..15fb3a117 100644 ++--- a/Source/DataStructureAndEncodingDefinition/gdcmElement.h +++++ b/Source/DataStructureAndEncodingDefinition/gdcmElement.h ++@@ -473,7 +473,7 @@ public: ++ assert( _is ); // Is stream valid ? ++ _is.read( reinterpret_cast(data+0), type_size); ++ for(unsigned long i=1; i(data+i), type_size ); ++ } ++ //ByteSwap::SwapRangeFromSwapCodeIntoSystem(data, ++@@ -489,7 +489,7 @@ public: ++ assert( _is ); // Is stream valid ? ++ _is.read( reinterpret_cast(data+0), type_size); ++ for(unsigned long i=1; i(data+i), type_size ); ++ } ++ //ByteSwap::SwapRangeFromSwapCodeIntoSystem(data, ++diff --git a/Source/MediaStorageAndFileFormat/gdcmLookupTable.cxx b/Source/MediaStorageAndFileFormat/gdcmLookupTable.cxx ++index 0d5a99c40..2c566923b 100644 ++--- a/Source/MediaStorageAndFileFormat/gdcmLookupTable.cxx +++++ b/Source/MediaStorageAndFileFormat/gdcmLookupTable.cxx ++@@ -130,7 +130,10 @@ void LookupTable::SetLUT(LookupTableType type, const unsigned char *array, ++ ++ if( !IncompleteLUT ) ++ { ++- assert( Internal->RGB.size() == 3*Internal->Length[type]*(BitSample/8) ); +++ if( Internal->RGB.size() != 3*Internal->Length[type]*(BitSample/8) ) { +++ gdcmErrorMacro( "Invalid length for LUT data" ); +++ return; +++ } ++ } ++ // Too funny: 05115014-mr-siemens-avanto-syngo-with-palette-icone.dcm ++ // There is pseudo PALETTE_COLOR LUT in the Icon, if one look carefully the LUT values ++diff --git a/Source/MediaStorageAndFileFormat/gdcmPixmapReader.cxx b/Source/MediaStorageAndFileFormat/gdcmPixmapReader.cxx ++index 9c30ff8b9..258a23c1f 100644 ++--- a/Source/MediaStorageAndFileFormat/gdcmPixmapReader.cxx +++++ b/Source/MediaStorageAndFileFormat/gdcmPixmapReader.cxx ++@@ -306,8 +306,12 @@ static void DoIconImage(const DataSet& rootds, Pixmap& image) ++ unsigned long check = ++ (el_us3.GetValue(0) ? el_us3.GetValue(0) : 65536) ++ * el_us3.GetValue(2) / 8; ++- assert( check == lut_raw->GetLength() || 2 * check == lut_raw->GetLength() ++- || check + 1 == lut_raw->GetLength() ); (void)check; +++ if(!( check == lut_raw->GetLength() || 2 * check == lut_raw->GetLength() +++ || check + 1 == lut_raw->GetLength() )) { +++ gdcmErrorMacro( "Icon Sequence is invalid. Giving up" ); +++ pixeldata.Clear(); +++ return; +++ } ++ } ++ else if( ds.FindDataElement( seglut ) ) ++ { +diff -Nru gdcm-3.0.21/debian/patches/CVE-2024-25569.patch gdcm-3.0.21/debian/patches/CVE-2024-25569.patch +--- gdcm-3.0.21/debian/patches/CVE-2024-25569.patch 1970-01-01 00:00:00.000000000 +0000 ++++ gdcm-3.0.21/debian/patches/CVE-2024-25569.patch 2026-11-05 20:35:37.000000000 +0000 +@@ -0,0 +1,36 @@ ++commit dda17aa8d5939e4e255ebba67aacf34b09d88692 ++Author: Mathieu Malaterre ++Date: Wed Feb 21 02:44:55 2024 -0800 ++ ++ Remove symptoms from TALOS-2024-1944 ++ ++diff --git a/Source/MediaStorageAndFileFormat/gdcmRAWCodec.cxx b/Source/MediaStorageAndFileFormat/gdcmRAWCodec.cxx ++index 19f739399..46392461e 100644 ++--- a/Source/MediaStorageAndFileFormat/gdcmRAWCodec.cxx +++++ b/Source/MediaStorageAndFileFormat/gdcmRAWCodec.cxx ++@@ -112,9 +112,7 @@ bool RAWCodec::DecodeBytes(const char* inBytes, size_t inBufferLength, ++ if(!r) return false; ++ ++ std::string str = os.str(); ++- //std::string::size_type check = str.size();//unused ++ ++- ++ if( this->GetPixelFormat() == PixelFormat::UINT12 || ++ this->GetPixelFormat() == PixelFormat::INT12 ) ++ { ++@@ -135,7 +133,14 @@ bool RAWCodec::DecodeBytes(const char* inBytes, size_t inBufferLength, ++ // DermaColorLossLess.dcm ++ //assert (check == inOutBufferLength || check == inOutBufferLength + 1); ++ // problem with: SIEMENS_GBS_III-16-ACR_NEMA_1.acr ++- memcpy(outBytes, str.c_str(), inOutBufferLength); +++ size_t len = str.size(); +++ if( inOutBufferLength <= len ) +++ memcpy(outBytes, str.c_str(), inOutBufferLength); +++ else +++ { +++ gdcmWarningMacro( "Requesting too much data. Truncating result" ); +++ memcpy(outBytes, str.c_str(), len); +++ } ++ } ++ ++ return r; +diff -Nru gdcm-3.0.21/debian/patches/CVE-2025-11266.patch gdcm-3.0.21/debian/patches/CVE-2025-11266.patch +--- gdcm-3.0.21/debian/patches/CVE-2025-11266.patch 1970-01-01 00:00:00.000000000 +0000 ++++ gdcm-3.0.21/debian/patches/CVE-2025-11266.patch 2026-11-05 20:35:37.000000000 +0000 +@@ -0,0 +1,25 @@ ++From 5829c95c8ac3afa9a3a3413675e948959c28a789 Mon Sep 17 00:00:00 2001 ++From: Mathieu Malaterre ++Date: Fri, 26 Sep 2025 10:04:53 +0200 ++Subject: [PATCH] Fix VU#591834.1 ++Original report is: ++Vulnerability VU#591834.1 (VU#591834) ++Date Added: 2025-08-21 ++Description: An out-of-bounds read vulnerability exists in the Grassroots DICOM library (GDCM), specifically within the SequenceOfFragments::ReadValue method. The issue is triggered during parsing of a malformed DICOM file containing encapsulated PixelData fragments (compressed image data stored as multiple fragments). ++Origin: https://github.com/malaterre/GDCM/commit/5829c95c8ac3afa9a3a3413675e948959c28a789 ++Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2025-11266 ++Bug-Debian: htts://bugs.debian.org/1122862 ++--- ++ .../gdcmSequenceOfFragments.h | 2 +- ++ 1 file changed, 1 insertion(+), 1 deletion(-) ++--- a/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.h +++++ b/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.h ++@@ -237,7 +237,7 @@ ++ const size_t lastf = Fragments.size() - 1; ++ const ByteValue *bv = Fragments[ lastf ].GetByteValue(); ++ const char *a = bv->GetPointer(); ++- gdcmAssertAlwaysMacro( (unsigned char)a[ bv->GetLength() - 3 ] == 0xfe ); +++ gdcmAssertAlwaysMacro( bv->GetLength() >= 3 && (unsigned char)a[ bv->GetLength() - 3 ] == 0xfe ); ++ Fragments[ lastf ].SetByteValue( bv->GetPointer(), bv->GetLength() - 3 ); ++ is.seekg( -11, std::ios::cur ); ++ assert( is.good() ); +diff -Nru gdcm-3.0.21/debian/patches/CVE-2025-48429.patch gdcm-3.0.21/debian/patches/CVE-2025-48429.patch +--- gdcm-3.0.21/debian/patches/CVE-2025-48429.patch 1970-01-01 00:00:00.000000000 +0000 ++++ gdcm-3.0.21/debian/patches/CVE-2025-48429.patch 2026-11-05 20:35:37.000000000 +0000 +@@ -0,0 +1,189 @@ ++From: pierre ++Date: Thu, 8 Jan 2026 10:36:10 +0100 ++Subject: [PATCH] Refactor the RLE header to ensure it conforms to the DICOM ++ standard. ++ ++Origin: https://github.com/malaterre/GDCM/commit/0393310f8bb27c3bec8b67c6bfb18f71f6a15bb8 ++Bug-Debian: https://bugs.debian.org/1123589 ++Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2025-48429 ++Bug-Freexian-Security: https://deb.freexian.com/extended-lts/tracker/CVE-2025-48429 ++--- ++ .../gdcmRLECodec.cxx | 105 +++++++++++++----- ++ 1 file changed, 76 insertions(+), 29 deletions(-) ++ ++--- a/Source/MediaStorageAndFileFormat/gdcmRLECodec.cxx +++++ b/Source/MediaStorageAndFileFormat/gdcmRLECodec.cxx ++@@ -24,6 +24,7 @@ ++ #include // req C++11 ++ #include // ptrdiff_t fix ++ #include +++#include ++ ++ #include ++ ++@@ -33,37 +34,73 @@ ++ // TODO ideally this code should be in utilities for ease of reuse ++ class RLEHeader ++ { ++-public: +++private: ++ uint32_t NumSegments; ++ uint32_t Offset[15]; +++public: +++ uint32_t GetNumSegments() const { return NumSegments; } +++ bool SetNumSegments(uint32_t num) +++ { +++ if (num > 15) +++ { +++ gdcmErrorMacro("Number of segments cannot be bigger than 15"); +++ return false; +++ } +++ NumSegments = num; +++ return true; +++ }; +++ bool SetOffset(const std::array &offset) +++ { +++ std::copy(offset.begin(), offset.end(), Offset); +++ return true; +++ }; +++ uint32_t GetOffset(size_t index) const +++ { +++ if (index < 15) return Offset[index]; +++ return 0; +++ }; +++ bool SetOffset(size_t index, uint32_t value) { +++ if (index >= 15) return false; +++ Offset[index] = value; +++ return true; +++ } ++ ++- void Print(std::ostream &os) +++ bool Read(std::istream &is) ++ { ++- os << "NumSegments:" << NumSegments << "\n"; ++- for(int i=0; i<15; ++i) ++- { ++- os << i << ":" << Offset[i] << "\n"; +++ // read Header (64 bytes) +++ uint32_t buffer[16] = {0}; +++ is.read(reinterpret_cast(buffer), 64); +++ if (static_cast(is.gcount()) != 64) +++ { +++ gdcmErrorMacro("RLE Header truncated: expected 64 bytes, got " << is.gcount()); +++ return false; +++ } +++ assert(sizeof(uint32_t) * 16 == 64); +++ SwapperNoOp::SwapArray(reinterpret_cast(buffer), 16); +++ if (!SetNumSegments(buffer[0])) return false; +++ memcpy(Offset, &buffer[1], sizeof(uint32_t) * 15); +++ if (NumSegments >= 1) { +++ if (Offset[0] != 64) return false; +++ } +++ // We just check that we are indeed at the proper position start+64 +++ return true; +++ } +++ void Print(std::ostream &os) +++ { +++ os << "NumSegments:" << NumSegments << "\n"; +++ for (int i = 0; i < 15; ++i) { +++ os << i << ":" << Offset[i] << "\n"; ++ } ++ } ++ }; ++ +++static_assert(sizeof(RLEHeader) == 64, "RLEHeader size must be 64 bits to comply with dicom standard"); ++ class RLEFrame ++ { ++ public: ++ bool Read(std::istream &is) ++ { ++- // read Header (64 bytes) ++- is.read((char*)(&Header), sizeof(uint32_t)*16); ++- assert( sizeof(uint32_t)*16 == 64 ); ++- assert( sizeof(RLEHeader) == 64 ); ++- SwapperNoOp::SwapArray((uint32_t*)&Header,16); ++- uint32_t numSegments = Header.NumSegments; ++- if( numSegments >= 1 ) ++- { ++- if( Header.Offset[0] != 64 ) return false; ++- } ++- // We just check that we are indeed at the proper position start+64 ++- return true; +++ return Header.Read(is); ++ } ++ void Print(std::ostream &os) ++ { ++@@ -379,7 +416,9 @@ ++ assert( MaxNumSegments % 3 == 0 ); ++ } ++ ++- RLEHeader header = { static_cast ( MaxNumSegments ), { 64 } }; +++ RLEHeader header; +++ header.SetNumSegments(static_cast(MaxNumSegments)); +++ header.SetOffset({64}); ++ // there cannot be any space in between the end of the RLE header and the start ++ // of the first RLE segment ++ // ++@@ -514,12 +553,12 @@ ++ length += llength; ++ } ++ // update header ++- header.Offset[1+seg] = (uint32_t)(header.Offset[seg] + length); +++ header.SetOffset(1 + seg, (uint32_t)(header.GetOffset(seg) + length)); ++ ++ assert( data.str().size() == length ); ++ datastr += data.str(); ++ } ++- header.Offset[MaxNumSegments] = 0; +++ header.SetOffset(MaxNumSegments, 0); ++ std::stringstream os; ++ //header.Print( std::cout ); ++ os.write((char*)&header,sizeof(header)); ++@@ -762,7 +801,7 @@ ++ RLEFrame &frame = Internals->Frame; ++ if( !frame.Read(is) ) ++ return false; ++- unsigned long numSegments = frame.Header.NumSegments; +++ unsigned long numSegments = frame.Header.GetNumSegments(); ++ ++ unsigned long numberOfReadBytes = 0; ++ ++@@ -796,7 +835,13 @@ ++ { ++ numberOfReadBytes = 0; ++ std::streampos pos = is.tellg() - start; ++- if ( frame.Header.Offset[i] - pos != 0 ) +++ if (frame.Header.GetOffset(i) > BufferLength) +++ { +++ gdcmErrorMacro("Offset is bigger then buffer Length"); +++ return false; +++ } +++ +++ if ( frame.Header.GetOffset(i) - pos != 0 ) ++ { ++ // ACUSON-24-YBR_FULL-RLE.dcm ++ // D_CLUNIE_CT1_RLE.dcm ++@@ -804,10 +849,10 @@ ++ //gdcmWarningMacro( "RLE Header says: " << frame.Header.Offset[i] << ++ // " when it should says: " << pos << std::endl ); ++- std::streamoff check = frame.Header.Offset[i] - pos;//should it be a streampos or a uint32? mmr +++ std::streamoff check = frame.Header.GetOffset(i) - pos;//should it be a streampos or a uint32? mmr ++ // check == 2 for gdcmDataExtra/gdcmSampleData/US_DataSet/GE_US/2929J686-breaker ++ //assert( check == 1 || check == 2); ++ (void)check; //warning removal ++- is.seekg( frame.Header.Offset[i] + start, std::ios::beg ); +++ is.seekg(frame.Header.GetOffset(i) + start, std::ios::beg); ++ } ++ ++ unsigned long numOutBytes = 0; ++@@ -860,8 +906,8 @@ ++ return false; ++ // numsegments = num_comp * bpp / 8; ++ // numsegments >0 && numsegments <= 12 ++- uint32_t bytespercomp = frame.Header.NumSegments; ++- if( frame.Header.NumSegments % 3 == 0 ) +++ uint32_t bytespercomp = frame.Header.GetNumSegments(); +++ if (frame.Header.GetNumSegments() % 3 == 0) ++ { ++ PI = PhotometricInterpretation::RGB; ++ PlanarConfiguration = 1; +diff -Nru gdcm-3.0.21/debian/patches/CVE-2025-52582.patch gdcm-3.0.21/debian/patches/CVE-2025-52582.patch +--- gdcm-3.0.21/debian/patches/CVE-2025-52582.patch 1970-01-01 00:00:00.000000000 +0000 ++++ gdcm-3.0.21/debian/patches/CVE-2025-52582.patch 2026-11-05 20:35:37.000000000 +0000 +@@ -0,0 +1,93 @@ ++Author: pleduff ++Date: Mon, 9 Nov 2020 12:29:45 +0100 ++ ++ Fix bug #512: Crash when reading corrupted Jpeg2000 files ++ ++ Prevent overlay extraction in case of malformed overlay or image information. ++ ++ Add warning to prevent user ++ ++Origin: https://github.com/malaterre/GDCM/commit/14825ceb1cb6855f32e726ee5cd2968e3051da2a ++Bug-Debian: https://bugs.debian.org/1123576 ++Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2025-52582 ++Bug-Freexian-Security: https://deb.freexian.com/extended-lts/tracker/CVE-2025-52582 ++ ++--- ++ Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx | 2 ++ ++ 1 file changed, 2 insertions(+) ++ ++--- a/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx +++++ b/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx ++@@ -1420,6 +1420,8 @@ ++ opj_stream_t *cio = nullptr; ++ opj_image_t *image = nullptr; ++ const unsigned char *src = (const unsigned char*)dummy_buffer; +++ if(!src) +++ return false ; ++ size_t file_length = buf_size; ++ ++ /* set decoding parameters to default values */ ++--- a/Source/MediaStorageAndFileFormat/gdcmPixmapReader.cxx +++++ b/Source/MediaStorageAndFileFormat/gdcmPixmapReader.cxx ++@@ -546,7 +546,44 @@ ++ { ++ gdcmWarningMacro( "Bits Allocated are wrong. Correcting." ); ++ ov.SetBitsAllocated( pixeldata.GetPixelFormat().GetBitsAllocated() ); ++- } +++ } +++ const DataElement &pixeldataDe = ds.GetDataElement(Tag(0x7fe0, 0x0010)); +++ const ByteValue *bv = pixeldataDe.GetByteValue(); +++ if (!bv) { +++ gdcmWarningMacro( +++ "Could not extract overlay from encapsulated stream."); +++ continue; +++ } +++ unsigned long computedFramePixelsNb = +++ pixeldata.GetDimension(0) * pixeldata.GetDimension(1); +++ +++ if (pixeldata.GetPixelFormat().GetPixelSize() == 0 || +++ computedFramePixelsNb > +++ bv->GetLength() / pixeldata.GetPixelFormat().GetPixelSize()) { +++ gdcmWarningMacro("Image information is not persistent. Can't extract overlay #" +++ << idxoverlays); +++ continue; +++ } +++ signed short ovOriginY = ov.GetOrigin()[0]; +++ signed short ovOriginX = ov.GetOrigin()[1]; +++ long startPixel = +++ (ovOriginX - 1) + (ovOriginY - 1) * pixeldata.GetDimension(0); +++ if (startPixel < 0 || +++ (unsigned long)startPixel >= computedFramePixelsNb) { +++ gdcmWarningMacro( +++ "Origin is not in image buffer. Can't extract overlay #" +++ << idxoverlays); +++ continue; +++ } +++ unsigned long lastPixelAccessed = +++ (unsigned long)startPixel + +++ (ov.GetRows() - 1) * pixeldata.GetDimension(0) + +++ (ov.GetColumns() - 1); +++ if (lastPixelAccessed >= computedFramePixelsNb) { +++ gdcmWarningMacro("Overlay not fit image buffer. Can't extract overlay " +++ << idxoverlays); +++ continue; +++ } ++ ++ if( !ov.GrabOverlayFromPixelData(ds) ) ++ { ++--- a/Source/MediaStorageAndFileFormat/gdcmOverlay.h +++++ b/Source/MediaStorageAndFileFormat/gdcmOverlay.h ++@@ -93,7 +93,12 @@ ++ ++ /// set overlay from byte array + length ++ void SetOverlay(const char *array, size_t length); ++- /// +++ +++ /// \warning Before calling this method, you must verify the consistency +++ /// between the image metadata (Image PixelFormat, Rows, Columns) and the +++ /// overlay parameters. This pre-verification is required to ensure that the +++ /// bit-depth is compatible and that the overlay data fits within the +++ /// allocated pixel storage. ++ bool GrabOverlayFromPixelData(DataSet const &ds); ++ ++ /// Return the Overlay Data as ByteValue: +diff -Nru gdcm-3.0.21/debian/patches/CVE-2025-53618_CVE-2025-53619-regression.patch gdcm-3.0.21/debian/patches/CVE-2025-53618_CVE-2025-53619-regression.patch +--- gdcm-3.0.21/debian/patches/CVE-2025-53618_CVE-2025-53619-regression.patch 1970-01-01 00:00:00.000000000 +0000 ++++ gdcm-3.0.21/debian/patches/CVE-2025-53618_CVE-2025-53619-regression.patch 2026-11-05 20:35:37.000000000 +0000 +@@ -0,0 +1,26 @@ ++From: Mathieu Malaterre ++Date: Mon, 29 Jun 2026 15:02:10 +0200 ++Subject: [PATCH] Accepth odd length ++ ++Fix regression f0e359c87947326c7fb2f7b91ecbe351e9d8c683 ++ ++The frame size check added by CVE-2025-53618_CVE-2025-53619.patch ++rejects a frame that carries the one byte of padding DICOM adds to ++odd-length values, so JPEG encoding (for example gdcmconv --jpeg) ++fails on images such as a 3x3 RGB one. ++ ++Origin: upstream, https://github.com/malaterre/GDCM/commit/9ced0f9ae1d6ecb9e84c2a06db36c9697815108f ++Applied-Upstream: 3.2.9 ++Last-Update: 2026-11-01 ++--- ++--- a/Source/MediaStorageAndFileFormat/gdcmJPEGBITSCodec.hxx +++++ b/Source/MediaStorageAndFileFormat/gdcmJPEGBITSCodec.hxx ++@@ -1171,7 +1171,7 @@ bool JPEGBITSCodec::InternalCode(const c ++ // Check if provided buffer correspond to image parameters for current frame ++ size_t expected_frame_size = (size_t)image_width * image_height * ++ this->GetPixelFormat().GetPixelSize(); ++- if (len != expected_frame_size) { +++ if (len != expected_frame_size && len != expected_frame_size + 1) { ++ gdcmErrorMacro("Frame size don't match"); ++ return false; ++ } +diff -Nru gdcm-3.0.21/debian/patches/CVE-2025-53618_CVE-2025-53619.patch gdcm-3.0.21/debian/patches/CVE-2025-53618_CVE-2025-53619.patch +--- gdcm-3.0.21/debian/patches/CVE-2025-53618_CVE-2025-53619.patch 1970-01-01 00:00:00.000000000 +0000 ++++ gdcm-3.0.21/debian/patches/CVE-2025-53618_CVE-2025-53619.patch 2026-11-05 20:35:37.000000000 +0000 +@@ -0,0 +1,31 @@ ++From: pierre ++Date: Thu, 8 Jan 2026 15:58:32 +0100 ++Subject: [PATCH] Add a frame size check to ensure that the provided data ++ corresponds to the buffer size ++ ++Origin: https://github.com/malaterre/GDCM/commit/f0e359c87947326c7fb2f7b91ecbe351e9d8c683 ++Bug-Debian: https://bugs.debian.org/1123587 ++Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2025-53618 ++Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2025-53619 ++Bug-Freexian-Security: https://deb.freexian.com/extended-lts/tracker/CVE-2025-53618 ++Bug-Freexian-Security: https://deb.freexian.com/extended-lts/tracker/CVE-2025-53619 ++--- ++ Source/MediaStorageAndFileFormat/gdcmJPEGBITSCodec.hxx | 7 +++++++ ++ 1 file changed, 7 insertions(+) ++ ++--- a/Source/MediaStorageAndFileFormat/gdcmJPEGBITSCodec.hxx +++++ b/Source/MediaStorageAndFileFormat/gdcmJPEGBITSCodec.hxx ++@@ -1166,6 +1166,13 @@ ++ int image_height = dims[1]; /* Number of rows in image */ ++ int image_width = dims[0]; /* Number of columns in image */ ++ +++ // Check if provided buffer correspond to image parameters for current frame +++ size_t expected_frame_size = (size_t)image_width * image_height * +++ this->GetPixelFormat().GetPixelSize(); +++ if (len != expected_frame_size) { +++ gdcmErrorMacro("Frame size don't match"); +++ return false; +++ } ++ /* This struct contains the JPEG compression parameters and pointers to ++ * working space (which is allocated as needed by the JPEG library). ++ * It is possible to have several such structures, representing multiple +diff -Nru gdcm-3.0.21/debian/patches/CVE-2026-3650.patch gdcm-3.0.21/debian/patches/CVE-2026-3650.patch +--- gdcm-3.0.21/debian/patches/CVE-2026-3650.patch 1970-01-01 00:00:00.000000000 +0000 ++++ gdcm-3.0.21/debian/patches/CVE-2026-3650.patch 2026-11-05 20:35:37.000000000 +0000 +@@ -0,0 +1,315 @@ ++From: Matt McCormick ++Date: Wed, 15 Apr 2026 16:24:50 -0400 ++Subject: [PATCH] Fix CVE-2026-3650: reject Value Length exceeding stream size ++ ++A crafted DICOM file could specify an arbitrarily large Value Length ++field (up to ~4 GB), causing ByteValue::SetLength() to attempt a ++massive memory allocation before any stream data is read. This enables ++denial-of-service via memory exhaustion. ++ ++Add stream-size validation in ExplicitDataElement::ReadValue(), ++ImplicitDataElement::ReadValue(), Fragment::ReadValue(), and ++Fragment::ReadBacktrack(). Before allocating a ByteValue, the code ++now compares the declared VL against the remaining bytes in the ++stream via tellg()/seekg(). Non-seekable streams skip the check ++gracefully. ++ ++Also fix out-of-bounds array accesses in SequenceOfFragments where ++bv->GetLength() - N was used without verifying minimum length, ++affecting lines that use gdcmAssertAlwaysMacro (active in release). ++ ++Add TestCVE20263650 covering Explicit VR, Implicit VR, and Fragment ++code paths with a 1 GB VL on a ~20-byte stream. ++ ++Origin: backport, https://github.com/malaterre/GDCM/commit/9d65a217c958968a74c14b10388d03ca61953a74 ++Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2026-3650 ++Bug-Freexian-Security: https://deb.freexian.com/extended-lts/tracker/CVE-2026-3650 ++Bug-Debian: htts://bugs.debian.org/1132042 ++--- ++ .../gdcmExplicitDataElement.txx | 17 +++ ++ .../gdcmFragment.h | 24 +++ ++ .../gdcmImplicitDataElement.txx | 17 +++ ++ .../gdcmSequenceOfFragments.h | 6 +- ++ .../Cxx/CMakeLists.txt | 1 + ++ .../Cxx/TestCVE20263650.cxx | 144 ++++++++++++++++++ ++ 6 files changed, 206 insertions(+), 3 deletions(-) ++ create mode 100644 Testing/Source/DataStructureAndEncodingDefinition/Cxx/TestCVE20263650.cxx ++ ++--- a/Source/DataStructureAndEncodingDefinition/gdcmExplicitDataElement.txx +++++ b/Source/DataStructureAndEncodingDefinition/gdcmExplicitDataElement.txx ++@@ -237,6 +237,23 @@ std::istream &ExplicitDataElement::ReadV ++ { ++ //assert( TagField != Tag(0x7fe0,0x0010) ); ++ ValueField = new ByteValue; +++ if( readvalues ) +++ { +++ const std::streampos cur = is.tellg(); +++ if( cur != std::streampos(-1) ) +++ { +++ is.seekg(0, std::ios::end); +++ const std::streampos end = is.tellg(); +++ is.seekg(cur); +++ if( end != std::streampos(-1) && is.good() +++ && static_cast(end - cur) < static_cast(ValueLengthField) ) +++ { +++ gdcmWarningMacro( "Value Length " << ValueLengthField +++ << " exceeds remaining stream size for tag " << TagField ); +++ throw Exception( "Value Length exceeds remaining stream size" ); +++ } +++ } +++ } ++ } ++ // We have the length we should be able to read the value ++ this->SetValueFieldLength( ValueLengthField, readvalues ); ++--- a/Source/DataStructureAndEncodingDefinition/gdcmFragment.h +++++ b/Source/DataStructureAndEncodingDefinition/gdcmFragment.h ++@@ -95,6 +95,18 @@ public: ++ const Tag seqDelItem(0xfffe,0xe0dd); ++ // Self ++ SmartPointer bv = new ByteValue; +++ const std::streampos cur = is.tellg(); +++ if( cur != std::streampos(-1) ) +++ { +++ is.seekg(0, std::ios::end); +++ const std::streampos end = is.tellg(); +++ is.seekg(cur); +++ if( end != std::streampos(-1) && is.good() +++ && static_cast(end - cur) < static_cast(ValueLengthField) ) +++ { +++ throw Exception( "Fragment Value Length exceeds remaining stream size" ); +++ } +++ } ++ bv->SetLength(ValueLengthField); ++ if( !bv->Read(is) ) ++ { ++@@ -148,6 +160,18 @@ public: ++ ++ // Self ++ SmartPointer bv = new ByteValue; +++ const std::streampos cur2 = is.tellg(); +++ if( cur2 != std::streampos(-1) ) +++ { +++ is.seekg(0, std::ios::end); +++ const std::streampos end2 = is.tellg(); +++ is.seekg(cur2); +++ if( end2 != std::streampos(-1) && is.good() +++ && static_cast(end2 - cur2) < static_cast(ValueLengthField) ) +++ { +++ throw Exception( "Fragment Value Length exceeds remaining stream size" ); +++ } +++ } ++ bv->SetLength(ValueLengthField); ++ if( !bv->Read(is) ) ++ { ++--- a/Source/DataStructureAndEncodingDefinition/gdcmImplicitDataElement.txx +++++ b/Source/DataStructureAndEncodingDefinition/gdcmImplicitDataElement.txx ++@@ -215,6 +215,23 @@ std::istream &ImplicitDataElement::ReadV ++ ValueLengthField = 202; // 0xca ++ } ++ #endif +++ if( !ValueLengthField.IsUndefined() && readvalues ) +++ { +++ const std::streampos cur = is.tellg(); +++ if( cur != std::streampos(-1) ) +++ { +++ is.seekg(0, std::ios::end); +++ const std::streampos end = is.tellg(); +++ is.seekg(cur); +++ if( end != std::streampos(-1) && is.good() +++ && static_cast(end - cur) < static_cast(ValueLengthField) ) +++ { +++ gdcmWarningMacro( "Value Length " << ValueLengthField +++ << " exceeds remaining stream size for tag " << TagField ); +++ throw Exception( "Value Length exceeds remaining stream size" ); +++ } +++ } +++ } ++ // We have the length we should be able to read the value ++ this->SetValueFieldLength( ValueLengthField, readvalues ); ++ bool failed; ++--- a/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.h +++++ b/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.h ++@@ -167,7 +167,7 @@ std::istream& ReadValue(std::istream &is ++ { ++ assert( Fragments.size() == 1 ); ++ const ByteValue *bv = Fragments[0].GetByteValue(); ++- assert( (unsigned char)bv->GetPointer()[ bv->GetLength() - 1 ] == 0xfe ); +++ assert( bv->GetLength() >= 1 && (unsigned char)bv->GetPointer()[ bv->GetLength() - 1 ] == 0xfe ); ++ // Yes this is an extra copy, this is a bug anyway, go fix YOUR code ++ Fragments[0].SetByteValue( bv->GetPointer(), bv->GetLength() - 1 ); ++ gdcmWarningMacro( "JPEG Fragment length was declared with an extra byte" ++@@ -188,7 +188,7 @@ std::istream& ReadValue(std::istream &is ++ const size_t lastf = Fragments.size() - 1; ++ const ByteValue *bv = Fragments[ lastf ].GetByteValue(); ++ const char *a = bv->GetPointer(); ++- gdcmAssertAlwaysMacro( (unsigned char)a[ bv->GetLength() - 1 ] == 0xfe ); +++ gdcmAssertAlwaysMacro( bv->GetLength() >= 1 && (unsigned char)a[ bv->GetLength() - 1 ] == 0xfe ); ++ Fragments[ lastf ].SetByteValue( bv->GetPointer(), bv->GetLength() - 1 ); ++ is.seekg( -9, std::ios::cur ); ++ assert( is.good() ); ++@@ -212,7 +212,7 @@ std::istream& ReadValue(std::istream &is ++ const size_t lastf = Fragments.size() - 1; ++ const ByteValue *bv = Fragments[ lastf ].GetByteValue(); ++ const char *a = bv->GetPointer(); ++- gdcmAssertAlwaysMacro( (unsigned char)a[ bv->GetLength() - 2 ] == 0xfe ); +++ gdcmAssertAlwaysMacro( bv->GetLength() >= 2 && (unsigned char)a[ bv->GetLength() - 2 ] == 0xfe ); ++ Fragments[ lastf ].SetByteValue( bv->GetPointer(), bv->GetLength() - 2 ); ++ is.seekg( -10, std::ios::cur ); ++ assert( is.good() ); ++--- a/Testing/Source/DataStructureAndEncodingDefinition/Cxx/CMakeLists.txt +++++ b/Testing/Source/DataStructureAndEncodingDefinition/Cxx/CMakeLists.txt ++@@ -47,6 +47,7 @@ set(DSED_TEST_SRCS ++ TestVL.cxx ++ TestVM.cxx ++ TestVR.cxx +++ TestCVE20263650.cxx ++ #TestValue.cxx ++ #TestTorture.cxx ++ TestElement2.cxx ++--- /dev/null +++++ b/Testing/Source/DataStructureAndEncodingDefinition/Cxx/TestCVE20263650.cxx ++@@ -0,0 +1,144 @@ +++/*========================================================================= +++ +++ Program: GDCM (Grassroots DICOM). A DICOM library +++ +++ Copyright (c) 2006-2011 Mathieu Malaterre +++ All rights reserved. +++ See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details. +++ +++ This software is distributed WITHOUT ANY WARRANTY; without even +++ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +++ PURPOSE. See the above copyright notice for more information. +++ +++=========================================================================*/ +++#include "gdcmExplicitDataElement.h" +++#include "gdcmImplicitDataElement.h" +++#include "gdcmFragment.h" +++#include "gdcmSwapper.h" +++ +++#include +++#include +++ +++// CVE-2026-3650: Verify that crafted DICOM data elements with a Value Length +++// exceeding the remaining stream size are rejected without attempting the +++// allocation. +++ +++static int TestExplicitVR() +++{ +++ // Explicit VR data element: Tag (0008,0060), VR = OB, VL = 1 GB, 10 bytes data +++ std::stringstream ss; +++ const uint16_t group = 0x0008; +++ const uint16_t element = 0x0060; +++ ss.write(reinterpret_cast(&group), 2); +++ ss.write(reinterpret_cast(&element), 2); +++ ss.write("OB", 2); +++ const uint16_t reserved = 0; +++ ss.write(reinterpret_cast(&reserved), 2); +++ const uint32_t vl = 0x40000000; +++ ss.write(reinterpret_cast(&vl), 4); +++ const char data[10] = {}; +++ ss.write(data, sizeof(data)); +++ +++ gdcm::ExplicitDataElement de; +++ try +++ { +++ de.Read(ss); +++ std::cerr << "ERROR: ExplicitDataElement::Read should have thrown" << std::endl; +++ return 1; +++ } +++ catch(const gdcm::Exception &) +++ { +++ return 0; +++ } +++ catch(const std::bad_alloc &) +++ { +++ std::cerr << "ERROR: ExplicitDataElement allocated memory for oversized VL" << std::endl; +++ return 1; +++ } +++ catch(...) +++ { +++ std::cerr << "ERROR: ExplicitDataElement::Read threw unexpected exception" << std::endl; +++ return 1; +++ } +++} +++ +++static int TestImplicitVR() +++{ +++ // Implicit VR data element: Tag (0008,0060), VL = 1 GB, 10 bytes data +++ std::stringstream ss; +++ const uint16_t group = 0x0008; +++ const uint16_t element = 0x0060; +++ ss.write(reinterpret_cast(&group), 2); +++ ss.write(reinterpret_cast(&element), 2); +++ const uint32_t vl = 0x40000000; +++ ss.write(reinterpret_cast(&vl), 4); +++ const char data[10] = {}; +++ ss.write(data, sizeof(data)); +++ +++ gdcm::ImplicitDataElement de; +++ try +++ { +++ de.Read(ss); +++ std::cerr << "ERROR: ImplicitDataElement::Read should have thrown" << std::endl; +++ return 1; +++ } +++ catch(const gdcm::Exception &) +++ { +++ return 0; +++ } +++ catch(const std::bad_alloc &) +++ { +++ std::cerr << "ERROR: ImplicitDataElement allocated memory for oversized VL" << std::endl; +++ return 1; +++ } +++ catch(...) +++ { +++ std::cerr << "ERROR: ImplicitDataElement::Read threw unexpected exception" << std::endl; +++ return 1; +++ } +++} +++ +++static int TestFragment() +++{ +++ // Fragment: Item tag (fffe,e000), VL = 1 GB, 10 bytes data +++ std::stringstream ss; +++ const uint16_t group = 0xfffe; +++ const uint16_t element = 0xe000; +++ ss.write(reinterpret_cast(&group), 2); +++ ss.write(reinterpret_cast(&element), 2); +++ const uint32_t vl = 0x40000000; +++ ss.write(reinterpret_cast(&vl), 4); +++ const char data[10] = {}; +++ ss.write(data, sizeof(data)); +++ +++ gdcm::Fragment frag; +++ try +++ { +++ frag.Read(ss); +++ std::cerr << "ERROR: Fragment::Read should have thrown" << std::endl; +++ return 1; +++ } +++ catch(const gdcm::Exception &) +++ { +++ return 0; +++ } +++ catch(const std::bad_alloc &) +++ { +++ std::cerr << "ERROR: Fragment allocated memory for oversized VL" << std::endl; +++ return 1; +++ } +++ catch(...) +++ { +++ std::cerr << "ERROR: Fragment::Read threw unexpected exception" << std::endl; +++ return 1; +++ } +++} +++ +++int TestCVE20263650(int, char *[]) +++{ +++ int ret = 0; +++ ret += TestExplicitVR(); +++ ret += TestImplicitVR(); +++ ret += TestFragment(); +++ return ret; +++} +diff -Nru gdcm-3.0.21/debian/patches/series gdcm-3.0.21/debian/patches/series +--- gdcm-3.0.21/debian/patches/series 2023-01-29 11:58:27.000000000 +0000 ++++ gdcm-3.0.21/debian/patches/series 2026-11-05 20:35:37.000000000 +0000 +@@ -2,3 +2,12 @@ + 02_fixhurd.patch + 03_linkvtkdoc.patch + 04_multiarch.patch ++CVE-2024-25569.patch ++CVE-2024-22391.patch ++CVE-2024-22373.patch ++CVE-2025-11266.patch ++CVE-2025-52582.patch ++CVE-2025-53618_CVE-2025-53619.patch ++CVE-2025-53618_CVE-2025-53619-regression.patch ++CVE-2025-48429.patch ++CVE-2026-3650.patch diff --git a/gdcm/debian/trixie-pu-request.md b/gdcm/debian/trixie-pu-request.md index fa6c0f1..85d2088 100644 --- a/gdcm/debian/trixie-pu-request.md +++ b/gdcm/debian/trixie-pu-request.md @@ -1,13 +1,9 @@ - @@ -91,7 +87,7 @@ unstable. The bullseye LTS update DLA-4652-1 shipped the same CVE fixes. [ Checklist ] [x] *all* changes are documented in the d/changelog - [ ] I reviewed all changes and I approve them + [x] I reviewed all changes and I approve them [x] attach debdiff against the package in (old)stable [x] the issue is verified as fixed in unstable @@ -124,3 +120,8 @@ Unstable (3.0.24-14) does not have upstream 9ced0f9 yet. The same patch is proposed there in #1152837 (https://bugs.debian.org/1152837). I am not a Debian member, so the upload will need a sponsor from the Debian Med team. + +Emmanuel Arias and Andreas Tille agreed on debian-med to this update +going in this way. The changes are on a branch against debian/trixie +(med-team/gdcm on salsa); I will open the merge request as soon as my +salsa account is approved and add the link here. diff --git a/invesalius/CVE-2024-44825.patch b/invesalius/CVE-2024-44825.patch new file mode 100644 index 0000000..a9ba961 --- /dev/null +++ b/invesalius/CVE-2024-44825.patch @@ -0,0 +1,60 @@ +Description: Do not write outside of the project directory when opening .inv3 files + Extract() wrote every member of an .inv3 archive to + os.path.join(folder, member name) without checking the name, so a crafted + project file could create or overwrite any file the user can write + (CVE-2024-44825). + . + Extract the members with tarfile's "data" filter instead. Upstream does the + same since e4dda58, with tar_filter. The file list returned to the caller + is built from the filtered members, so it only has paths inside of the + destination directory. The mkdir of the first member's directory is + dropped: its name came from the archive as well, and tar.extract() creates + the directory itself. +Author: Valentín Torassa +Origin: backport, https://github.com/invesalius/invesalius3/commit/e4dda58f5c9937af0c34d483ffc267168e47cf58 +Bug: https://github.com/invesalius/invesalius3/issues/1404 +Bug-Debian: https://bugs.debian.org/1136204 +Last-Update: 2026-11-10 +--- +This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ +--- a/invesalius/project.py ++++ b/invesalius/project.py +@@ -493,19 +493,16 @@ + folder = decode(folder, const.FS_ENCODE) + + tar = tarfile.open(filename, "r") +- idir = decode(os.path.split(tar.getnames()[0])[0], 'utf8') +- os.mkdir(os.path.join(folder, idir)) + filelist = [] + for t in tar.getmembers(): +- fsrc = tar.extractfile(t) ++ # The "data" filter keeps every member inside of folder: it strips ++ # leading slashes and refuses "..", links that point outside and ++ # special files. It returns the member under the name it is ++ # extracted as, which is the one to report to the caller. ++ t = tarfile.data_filter(t, folder) ++ tar.extract(t, path=folder, filter="data") + fname = os.path.join(folder, decode(t.name, 'utf-8')) +- fdst = open(fname, 'wb') +- shutil.copyfileobj(fsrc, fdst) + filelist.append(fname) +- fsrc.close() +- fdst.close() +- del fsrc +- del fdst + tar.close() + return filelist + +@@ -513,7 +510,10 @@ + def Extract_(filename, folder): + tar = tarfile.open(filename, "r:gz") + #tar.list(verbose=True) +- tar.extractall(folder) +- filelist = [os.path.join(folder, i) for i in tar.getnames()] ++ filelist = [] ++ for t in tar.getmembers(): ++ t = tarfile.data_filter(t, folder) ++ tar.extract(t, path=folder, filter="data") ++ filelist.append(os.path.join(folder, t.name)) + tar.close() + return filelist diff --git a/invesalius/debian/bug-1136204-reply.md b/invesalius/debian/bug-1136204-reply.md new file mode 100644 index 0000000..f3c6632 --- /dev/null +++ b/invesalius/debian/bug-1136204-reply.md @@ -0,0 +1,81 @@ + +--- + +Control: tags -1 + patch + +Hi, + +Christoph asked in July whether someone could test his patch with a +compressed and an uncompressed .inv3 file. I did that today. I am also +attaching a shorter patch that I had prepared for the same problem, in +case it is useful to have both. + +Setup: 3.1.99998-8 rebuilt with dpkg-buildpackage in a fresh debian:sid +container (amd64, Python 3.14.10), once with Christoph's +0011-fix-cve-2024-44825.patch as it is on his salsa repository today, +and once with the attached patch. Each build was installed in the +container and tested as an unprivileged user. + +Both builds give the same results: + +- debian/tests/run-unit-test passes. +- Cranium.inv3 from invesalius-examples is a tar.gz. I repacked it as a + plain tar as well. Extract() returns the same 11 files with the same + contents for both forms, and so does Extract_() for the tar.gz. +- "invesalius3 --no-gui --export-project out.hdf5" works with + both forms. The two HDF5 files are equal except for the export date. +- Four crafted projects write nothing outside of the destination + directory: a member with "..", a member with an absolute name, a + symlink followed by a member that goes through it, and a first member + in an absolute directory. The unpatched code writes outside in three + of the four cases. I ran that part with 3.1.99998-7 in trixie, whose + project.py is identical to the one in -8. + +The differences I see between the two patches: + +- Christoph's patch checks the names itself and raises ValueError on the + first unsafe member, so such a project is rejected as a whole. The + attached one uses tarfile's "data" filter, the mechanism upstream uses + (with tar_filter). It strips a leading "/" and extracts that member + inside of the destination. For "..", for links that point outside and + for special files it raises a tarfile.FilterError. The list of files + that Extract() returns is built from the filtered members. +- The attached patch is smaller (11 lines added and 11 removed, against + 70 and 25), which may matter for a stable update. It needs Python 3.12 + or later. Unstable has 3.14 and trixie has 3.13. +- In Christoph's patch the helper within_dest() is defined but never + called. The check that does the work is the abspath()/startswith() one + further down, so this is only cosmetic. + +As far as I can tell either one fixes the problem, so please take +whichever you prefer. + +One more thing I noticed while testing: invesalius-bin 3.1.99998-8 from +the archive does not work in unstable at the moment. It ships its +extension modules only as cpython-313 and has no dependency on the +Python version, so with python3 3.14 "from invesalius_cy import +floodfill" fails with an ImportError. Both "invesalius3 --no-gui" on the +sample project and debian/tests/run-unit-test stop there, which would +explain the failing autopkgtest in the migration excuses. A rebuild is +enough (both test builds above work), so the next upload fixes it. I can +file it as a separate bug if that helps. + +For trixie: 3.1.99998-7 is affected by this bug and by CVE-2024-42845 +(#1082875, fixed in unstable in -8). Both are marked no-dsa. I have a +3.1.99998-7+deb13u1 debdiff with the two fixes, built and tested the +same way in a trixie container. Once this bug is fixed in unstable I +would like to propose it to the team for a point release, if that is +welcome. + +Thanks, +Valentín Torassa diff --git a/invesalius/debian/invesalius_3.1.99998-7+deb13u1_trixie.debdiff b/invesalius/debian/invesalius_3.1.99998-7+deb13u1_trixie.debdiff new file mode 100644 index 0000000..c2f4ee5 --- /dev/null +++ b/invesalius/debian/invesalius_3.1.99998-7+deb13u1_trixie.debdiff @@ -0,0 +1,120 @@ +diff -Nru invesalius-3.1.99998/debian/changelog invesalius-3.1.99998/debian/changelog +--- invesalius-3.1.99998/debian/changelog 2025-02-16 13:50:44.000000000 +0000 ++++ invesalius-3.1.99998/debian/changelog 2026-11-10 14:30:10.000000000 +0000 +@@ -1,3 +1,15 @@ ++invesalius (3.1.99998-7+deb13u1) trixie; urgency=medium ++ ++ * Team upload. ++ * fix-cve-2024-42845.patch: from 3.1.99998-8. Remove eval() from the DICOM ++ reader: a crafted DICOM file could run arbitrary code (CVE-2024-42845, ++ Closes: #1082875). ++ * CVE-2024-44825.patch: extract .inv3 project files with the "data" filter ++ of tarfile, so that a crafted project cannot write outside of its ++ temporary directory (CVE-2024-44825, Closes: #1136204). ++ ++ -- Valentín Torassa Tue, 10 Nov 2026 11:40:00 -0300 ++ + invesalius (3.1.99998-7) unstable; urgency=medium + + * Team upload. +diff -Nru invesalius-3.1.99998/debian/patches/CVE-2024-44825.patch invesalius-3.1.99998/debian/patches/CVE-2024-44825.patch +--- invesalius-3.1.99998/debian/patches/CVE-2024-44825.patch 1970-01-01 00:00:00.000000000 +0000 ++++ invesalius-3.1.99998/debian/patches/CVE-2024-44825.patch 2026-11-10 14:40:00.000000000 +0000 +@@ -0,0 +1,60 @@ ++Description: Do not write outside of the project directory when opening .inv3 files ++ Extract() wrote every member of an .inv3 archive to ++ os.path.join(folder, member name) without checking the name, so a crafted ++ project file could create or overwrite any file the user can write ++ (CVE-2024-44825). ++ . ++ Extract the members with tarfile's "data" filter instead. Upstream does the ++ same since e4dda58, with tar_filter. The file list returned to the caller ++ is built from the filtered members, so it only has paths inside of the ++ destination directory. The mkdir of the first member's directory is ++ dropped: its name came from the archive as well, and tar.extract() creates ++ the directory itself. ++Author: Valentín Torassa ++Origin: backport, https://github.com/invesalius/invesalius3/commit/e4dda58f5c9937af0c34d483ffc267168e47cf58 ++Bug: https://github.com/invesalius/invesalius3/issues/1404 ++Bug-Debian: https://bugs.debian.org/1136204 ++Last-Update: 2026-11-10 ++--- ++This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ ++--- a/invesalius/project.py +++++ b/invesalius/project.py ++@@ -493,19 +493,16 @@ ++ folder = decode(folder, const.FS_ENCODE) ++ ++ tar = tarfile.open(filename, "r") ++- idir = decode(os.path.split(tar.getnames()[0])[0], 'utf8') ++- os.mkdir(os.path.join(folder, idir)) ++ filelist = [] ++ for t in tar.getmembers(): ++- fsrc = tar.extractfile(t) +++ # The "data" filter keeps every member inside of folder: it strips +++ # leading slashes and refuses "..", links that point outside and +++ # special files. It returns the member under the name it is +++ # extracted as, which is the one to report to the caller. +++ t = tarfile.data_filter(t, folder) +++ tar.extract(t, path=folder, filter="data") ++ fname = os.path.join(folder, decode(t.name, 'utf-8')) ++- fdst = open(fname, 'wb') ++- shutil.copyfileobj(fsrc, fdst) ++ filelist.append(fname) ++- fsrc.close() ++- fdst.close() ++- del fsrc ++- del fdst ++ tar.close() ++ return filelist ++ ++@@ -513,7 +510,10 @@ ++ def Extract_(filename, folder): ++ tar = tarfile.open(filename, "r:gz") ++ #tar.list(verbose=True) ++- tar.extractall(folder) ++- filelist = [os.path.join(folder, i) for i in tar.getnames()] +++ filelist = [] +++ for t in tar.getmembers(): +++ t = tarfile.data_filter(t, folder) +++ tar.extract(t, path=folder, filter="data") +++ filelist.append(os.path.join(folder, t.name)) ++ tar.close() ++ return filelist +diff -Nru invesalius-3.1.99998/debian/patches/fix-cve-2024-42845.patch invesalius-3.1.99998/debian/patches/fix-cve-2024-42845.patch +--- invesalius-3.1.99998/debian/patches/fix-cve-2024-42845.patch 1970-01-01 00:00:00.000000000 +0000 ++++ invesalius-3.1.99998/debian/patches/fix-cve-2024-42845.patch 2026-11-10 14:27:51.000000000 +0000 +@@ -0,0 +1,24 @@ ++From: Thiago Franco de Moraes ++Subject: Removed eval from dicom.py (#820) ++Origin: upstream, https://github.com/invesalius/invesalius3/commit/020cd6056c30105a870cfea99939282b6ec5640b ++ ++--- a/invesalius/reader/dicom.py +++++ b/invesalius/reader/dicom.py ++@@ -443,7 +443,7 @@ ++ except (KeyError): ++ return "" ++ if data: ++- return [eval(value) for value in data.split("\\")] +++ return [float(value) for value in data.split("\\")] ++ return "" ++ ++ def GetImageLocation(self): ++@@ -456,7 +456,7 @@ ++ """ ++ data = self.data_image[str(0x020)][str(0x1041)] ++ if data: ++- return eval(data) +++ return float(data) ++ return "" ++ ++ def GetImageOffset(self): +diff -Nru invesalius-3.1.99998/debian/patches/series invesalius-3.1.99998/debian/patches/series +--- invesalius-3.1.99998/debian/patches/series 2025-02-16 13:50:44.000000000 +0000 ++++ invesalius-3.1.99998/debian/patches/series 2026-11-10 14:30:10.000000000 +0000 +@@ -7,3 +7,5 @@ + python3.13 + fix-my-types.patch + workaround-dropped-inner1d.patch ++fix-cve-2024-42845.patch ++CVE-2024-44825.patch diff --git a/pydicom/CVE-2026-32711.patch b/pydicom/CVE-2026-32711.patch new file mode 100644 index 0000000..d745c39 --- /dev/null +++ b/pydicom/CVE-2026-32711.patch @@ -0,0 +1,560 @@ +Description: Reject Referenced File IDs that point outside of the File-set root + A crafted DICOMDIR could set ReferencedFileID to a path outside of the + File-set root. pydicom only checked that the path existed and then used it + in FileSet.copy(), FileSet.write() and when reading the instances, so files + outside of the File-set could be read, copied and, in some flows, moved or + deleted (CVE-2026-32711). + . + This is the fix that upstream cherry-picked to the 2.4 series for 2.4.5: + the changes to pydicom/fileset.py and their tests. The rest of that commit + (version number, CI configuration, typos in other files) is not included. +Author: Darcy Mason +Origin: upstream, https://github.com/pydicom/pydicom/commit/ed4ddeac21de09101ee0732a0a2168dd73491370 +Bug: https://github.com/pydicom/pydicom/security/advisories/GHSA-v856-2rf8-9f28 +Bug-Debian: https://bugs.debian.org/1131492 +Last-Update: 2026-11-10 +--- +This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ +diff --git a/pydicom/fileset.py b/pydicom/fileset.py +index 5549d6dd86..f4412a4dcf 100644 +--- a/pydicom/fileset.py ++++ b/pydicom/fileset.py +@@ -344,24 +344,47 @@ def _encode_record(self, force_implicit: bool = False) -> int: + + return len(fp.getvalue()) + +- @property +- def _file_id(self) -> Optional[Path]: ++ def file_id_path(self, root_path: Path) -> Path | None: + """Return the *Referenced File ID* as a :class:`~pathlib.Path`. + ++ Params ++ ------ ++ root_path : Path ++ The root path of the parent file set. ++ + Returns + ------- + pathlib.Path or None + The *Referenced File ID* from the directory record as a + :class:`pathlib.Path` or ``None`` if the element value is null. ++ ++ Raises ++ ------ ++ PermissionError ++ If the file ID points to a path outside the fileset root path. ++ ++ AttributeError ++ If the Referenced File ID is missing in the directory record. ++ ++ :meta private: + """ + if "ReferencedFileID" in self._record: + elem = self._record["ReferencedFileID"] ++ if elem.VM < 1: ++ return None + if elem.VM == 1: +- return Path(cast(str, self._record.ReferencedFileID)) +- if elem.VM > 1: +- return Path(*cast(List[str], self._record.ReferencedFileID)) +- +- return None ++ path = Path(cast(str, self._record.ReferencedFileID)) ++ else: ++ path = Path(*cast(list[str], self._record.ReferencedFileID)) ++ ++ if path is not None: ++ if path.anchor or not ( ++ (root_path / path).resolve().is_relative_to(root_path) ++ ): ++ raise PermissionError( ++ f"ReferencedFileID ('{path}') must be inside the DICOMDIR root path" ++ ) ++ return path + + raise AttributeError("No 'Referenced File ID' in the directory record") + +@@ -371,7 +394,7 @@ def file_set(self) -> "FileSet": + return self.root.file_set + + def __getitem__(self, key: Union[str, "RecordNode"]) -> "RecordNode": +- """Return the current node's child using it's ++ """Return the current node's child using its + :attr:`~pydicom.fileset.RecordNode.key` + """ + if isinstance(key, RecordNode): +@@ -524,8 +547,8 @@ def leaf_summary(node: "RecordNode", indent_char: str) -> List[str]: + for node in self: + indent = indent_char * node.depth + if node.children: +- s.append(f"{indent}{str(node)}") +- # Summarise any leaves at the next level ++ s.append(f"{indent}{node}") ++ # Summarize any leaves at the next level + for child in node.children: + if child.has_instance: + s.extend(leaf_summary(child, indent_char)) +@@ -931,9 +954,8 @@ def path(self) -> str: + return os.fspath(cast(Path, self._stage_path)) + + # If not staged for addition then File Set must exist on file system +- return os.fspath( +- cast(Path, self.file_set.path) / cast(Path, self.node._file_id) +- ) ++ root_path = self.file_set.root_path ++ return os.fspath(root_path / cast(Path, self.node.file_id_path(root_path))) + + @property + def SOPClassUID(self) -> UID: +@@ -966,7 +988,7 @@ def __init__(self, ds: Optional[DSPathType] = None) -> None: + to the DICOMDIR file. + """ + # The nominal path to the root of the File-set +- self._path: Optional[Path] = None ++ self._root_path: Path | None = None + # The root node of the record tree used to fill out the DICOMDIR's + # *Directory Record Sequence*. + # The tree for instances currently in the File-set +@@ -1212,7 +1234,7 @@ def clear(self) -> None: + """Clear the File-set.""" + self._tree.children = [] + self._instances = [] +- self._path = None ++ self._root_path = None + self._ds = Dataset() + self._id = None + self._uid = generate_uid() +@@ -1661,7 +1683,7 @@ def load( + ) + + try: +- path = Path(cast(str, ds.filename)).resolve(strict=True) ++ path = Path(ds.filename).resolve(strict=True) + except FileNotFoundError: + raise FileNotFoundError( + "Unable to load the File-set as the 'filename' attribute " +@@ -1692,7 +1714,7 @@ def load( + Optional[str], + ds.get("SpecificCharacterSetOfFileSetDescriptorFile", None) + ) +- self._path = path.parent ++ self._root_path = path.parent + self._ds = ds + + # Create the record tree +@@ -1701,20 +1723,17 @@ def load( + bad_instances = [] + for instance in self: + # Check that the referenced file exists +- file_id = instance.node._file_id +- if file_id is None: +- bad_instances.append(instance) +- continue +- ++ file_id = self._file_id_path(instance.node) ++ assert file_id is not None + try: + # self.path is already set at this point +- (cast(Path, self.path) / file_id).resolve(strict=True) ++ (self.root_path / file_id).resolve(strict=True) + except FileNotFoundError: + bad_instances.append(instance) + warnings.warn( + "The referenced SOP Instance for the directory record at " + f"offset {instance.node._offset} does not exist: " +- f"{cast(Path, self.path) / file_id}" ++ f"{self.root_path / file_id}" + ) + continue + +@@ -1726,6 +1745,31 @@ def load( + for instance in bad_instances: + self._instances.remove(instance) + ++ def _file_id_path(self, node: RecordNode) -> Path | None: ++ """Return the *Referenced File ID* from the given node ++ as a :class:`~pathlib.Path`. ++ ++ Parameters ++ ---------- ++ node: RecordNode ++ The node where the *Referenced File ID* resides. ++ ++ Returns ++ ------- ++ pathlib.Path or None ++ The *Referenced File ID* from the directory record as a ++ :class:`pathlib.Path` or ``None`` if the element value is null. ++ ++ Raises ++ ------ ++ PermissionError ++ If the file ID points to a path outside the fileset root path. ++ ++ AttributeError ++ If the Referenced File ID is missing in the directory record. ++ """ ++ return node.file_id_path(self.root_path) ++ + def _parse_records( + self, + ds: Dataset, +@@ -1782,7 +1826,10 @@ def recurse_node(node: RecordNode) -> None: + del node.parent[node] + + # The leaf node references the FileInstance +- if "ReferencedFileID" in node._record: ++ if ( ++ "ReferencedFileID" in node._record ++ and self._file_id_path(node) is not None ++ ): + node.instance = FileInstance(node) + self._instances.append(node.instance) + +@@ -1817,12 +1864,11 @@ def recurse_node(node: RecordNode) -> None: + for node in missing: + # Get the path to the orphaned instance + original_value = node._record.ReferencedFileID +- file_id = node._file_id +- if file_id is None: ++ if (file_id := self._file_id_path(node)) is None: + continue + + # self.path is set for an existing File Set +- path = cast(Path, self.path) / file_id ++ path = self.root_path / file_id + if node.record_type == "PRIVATE": + instance = self.add_custom(path, node) + else: +@@ -1832,14 +1878,29 @@ def recurse_node(node: RecordNode) -> None: + instance.node._record.ReferencedFileID = original_value + + @property +- def path(self) -> Optional[str]: ++ def root_path(self) -> Path: ++ """Return the absolute path to the File-set root directory as ++ :class:`pathlib.Path`. ++ ++ Raises ++ ------ ++ AttributeError ++ If the root path is not set. ++ """ ++ if self._root_path is None: ++ raise AttributeError("No root path set in the File-set") ++ ++ return self._root_path ++ ++ @property ++ def path(self) -> str | None: + """Return the absolute path to the File-set root directory as + :class:`str` (if set) or ``None`` otherwise. + """ +- if self._path is not None: +- return os.fspath(self._path) ++ if self._root_path is not None: ++ return os.fspath(self._root_path) + +- return self._path ++ return None + + def _recordify(self, ds: Dataset) -> Iterator[Dataset]: + """Yield directory records for a SOP Instance. +@@ -2105,16 +2166,17 @@ def write( + ) + + if path: +- self._path = Path(path) ++ self._root_path = Path(path) + + # Don't write unless changed or new + if not self.is_staged: + return + + # Path to the DICOMDIR file +- p = cast(Path, self._path) / 'DICOMDIR' ++ root = self.root_path ++ p = root / "DICOMDIR" + +- # Re-use the existing directory structure if only moves or removals ++ # Reuse the existing directory structure if only moves or removals + # are required and `use_existing` is True + major_change = bool(self._stage['+']) + if use_existing and major_change: +@@ -2159,26 +2221,30 @@ def write( + # and copy any to the stage + fout = {Path(ii.FileID) for ii in self} + fin = { +- ii.node._file_id for ii in self +- if ii.SOPInstanceUID not in self._stage['+'] ++ self._file_id_path(ii.node) ++ for ii in self ++ if ii.SOPInstanceUID not in self._stage["+"] + } + collisions = fout & fin +- for instance in [ii for ii in self if ii.node._file_id in collisions]: +- self._stage['+'][instance.SOPInstanceUID] = instance +- instance._apply_stage('+') ++ for instance in [ ++ ii for ii in self if self._file_id_path(ii.node) in collisions ++ ]: ++ self._stage["+"][instance.SOPInstanceUID] = instance ++ instance._apply_stage("+") + shutil.copyfile( +- self._path / instance.node._file_id, instance.path ++ root / cast(Path, self._file_id_path(instance.node)), ++ instance.path, + ) + + for instance in self: +- dst = self._path / instance.FileID ++ dst = root / instance.FileID + dst.parent.mkdir(parents=True, exist_ok=True) + fn: Callable + if instance.SOPInstanceUID in self._stage['+']: + src = instance.path + fn = shutil.copyfile + else: +- src = self._path / instance.node._file_id ++ src = root / cast(Path, self._file_id_path(instance.node)) + fn = shutil.move + + fn(os.fspath(src), os.fspath(dst)) +diff --git a/pydicom/tests/conftest.py b/pydicom/tests/conftest.py +index 10d1dc3950..301fd009dc 100644 +--- a/pydicom/tests/conftest.py ++++ b/pydicom/tests/conftest.py +@@ -22,6 +22,14 @@ def allow_reading_invalid_values(): + config.settings.reading_validation_mode = value + + ++@pytest.fixture ++def ignore_reading_invalid_values(): ++ value = config.settings.reading_validation_mode ++ config.settings.reading_validation_mode = config.IGNORE ++ yield ++ config.settings.reading_validation_mode = value ++ ++ + @pytest.fixture + def enforce_writing_invalid_values(): + value = config.settings.writing_validation_mode +diff --git a/pydicom/tests/test_fileset.py b/pydicom/tests/test_fileset.py +index 40bd9d833c..8ded8862da 100644 +--- a/pydicom/tests/test_fileset.py ++++ b/pydicom/tests/test_fileset.py +@@ -1,5 +1,6 @@ + + import os ++import platform + import sys + from pathlib import Path + import shutil +@@ -10,7 +11,7 @@ + from pydicom import config, dcmread + from pydicom.data import get_testdata_file + from pydicom.dataset import Dataset, FileMetaDataset +-from pydicom.filebase import DicomBytesIO ++from pydicom.filebase import DicomBytesIO, DicomFileLike + from pydicom.fileset import ( + FileSet, FileInstance, RecordNode, is_conformant_file_id, + generate_filename, _define_patient, _define_study, _define_series, +@@ -81,6 +82,56 @@ def tdir(): + return TemporaryDirectory() + + ++FILESET_ROOT = "/path/to/fileset/" ++ABS_FILE_PATH = "/secret.txt" ++SYMLINK_TO_ABS_FILE = "Pat1/St1/Im2" ++SYMLINK_TO_ABS_DIR = "Pat1/St2" ++DOT_DOT_FILE = "../goback.txt" ++ABS_FILE_CONTENTS = "Top Secret file contents" ++COPY_PATH = "/path/to/copied/" ++ ++ ++@pytest.fixture( ++ params=[ ++ ABS_FILE_PATH, ++ DOT_DOT_FILE, ++ SYMLINK_TO_ABS_FILE, ++ SYMLINK_TO_ABS_DIR + ABS_FILE_PATH, ++ ] ++) ++def fileset_fs(request, fs, ignore_reading_invalid_values): ++ """Create an in-memory file system with pyfakefs and test DICOMDIRs""" ++ # Simplified version of submitted report from JeongAhn Jang, in pyfakefs ++ orig_dicomdir_root = Path(TEST_FILE).parent ++ dicomdir_root = Path(FILESET_ROOT) ++ fs.add_real_file( ++ orig_dicomdir_root / "77654033/CR1/6154", ++ target_path=dicomdir_root / "Pat1/St1/Im1", ++ ) ++ fs.create_file(ABS_FILE_PATH, contents=ABS_FILE_CONTENTS) ++ fs.create_dir(COPY_PATH) ++ fs.create_symlink(dicomdir_root / SYMLINK_TO_ABS_FILE, ABS_FILE_PATH) ++ fs.create_symlink(dicomdir_root / SYMLINK_TO_ABS_DIR, "/") ++ # MAKE DICOMDIR for this simplified file-set ++ fset = FileSet() ++ fset.add(dicomdir_root / "Pat1/St1/Im1") ++ fset.write(dicomdir_root) ++ ++ # Create bad DICOMDIR2 file from the simplified one ++ # Modify first referenced file ++ fset = FileSet(dicomdir_root / "DICOMDIR") ++ record = next( ++ rec for rec in fset._ds.DirectoryRecordSequence if "ReferencedFileID" in rec ++ ) ++ record.ReferencedFileID = request.param ++ ++ # Write modified DICOMDIR file ++ with open(dicomdir_root / "DICOMDIR2", "wb") as fp: ++ fset._write_dicomdir(DicomFileLike(fp)) ++ ++ yield fs ++ ++ + @pytest.fixture + def custom_leaf(): + """Return the leaf node from a custom 4-level record hierarchy""" +@@ -116,7 +167,7 @@ def custom_leaf(): + + + @pytest.fixture +-def private(dicomdir): ++def private(dicomdir, request, ignore_reading_invalid_values): + """Return a DICOMDIR dataset with PRIVATE records.""" + def write_record(ds): + """Return `ds` as explicit little encoded bytes.""" +@@ -143,9 +194,17 @@ def private_record(): + middle = private_record() + bottom = private_record() + bottom.ReferencedSOPClassUIDInFile = "1.2.3.4" +- bottom.ReferencedFileID = [ +- "TINY_ALPHA", "PT000000", "ST000000", "SE000000", "IM000000" +- ] ++ if hasattr(request, "param"): ++ file_ids = request.param ++ else: ++ file_ids = [ ++ "TINY_ALPHA", ++ "PT000000", ++ "ST000000", ++ "SE000000", ++ "IM000000", ++ ] ++ bottom.ReferencedFileID = file_ids + bottom.ReferencedSOPInstanceUIDInFile = ( + "1.2.276.0.7230010.3.1.4.0.31906.1359940846.78187" + ) +@@ -647,6 +706,15 @@ def test_key_raises(self, dummy): + with pytest.raises(AttributeError, match=msg): + instance.node.key + ++ @pytest.mark.parametrize("private", [["/", "etc", "passwd"]], indirect=True) ++ def test_id_outside_root(self, private): ++ """File ID points to a path outside the root directory.""" ++ with pytest.raises( ++ PermissionError, ++ match=r"ReferencedFileID .* must be inside the DICOMDIR root path", ++ ): ++ FileSet(private) ++ + def test_bad_record(self, private): + """Test a bad directory record raises an exception when loading.""" + del private.DirectoryRecordSequence[0].PatientID +@@ -709,7 +777,33 @@ def test_file_id_singleton(self, ct, tdir): + item.ReferencedFileID = "01" + ds.save_as(p / "DICOMDIR") + fs = FileSet(ds) +- assert fs._instances[0].node._file_id == Path("01") ++ assert fs._instances[0].node.file_id_path(fs.root_path) == Path("01") ++ ++ def test_absolute_file_id(self, ct, tdir, ignore_reading_invalid_values): ++ """Test a singleton File ID.""" ++ fs = FileSet() ++ p = Path(tdir.name) ++ ct.save_as(p / "01") ++ fs.add(p / "01") ++ fs.write(p) ++ ds = dcmread(p / "DICOMDIR") ++ item = ds.DirectoryRecordSequence[-1] ++ item.ReferencedFileID = "/01" ++ ds.save_as(p / "DICOMDIR") ++ with pytest.raises( ++ PermissionError, ++ match=r"ReferencedFileID .* must be inside the DICOMDIR root path", ++ ): ++ FileSet(ds) ++ ++ def test_root_path_missing(self, ct): ++ """Test RecordNode._file_id if no Referenced File ID.""" ++ fs = FileSet() ++ instance = fs.add(ct) ++ # del instance.node._record.ReferencedFileID ++ msg = r"No root path set in the File-set" ++ with pytest.raises(AttributeError, match=msg): ++ fs.root_path + + def test_file_id_missing(self, ct): + """Test RecordNode._file_id if no Referenced File ID.""" +@@ -718,7 +812,7 @@ def test_file_id_missing(self, ct): + del instance.node._record.ReferencedFileID + msg = r"No 'Referenced File ID' in the directory record" + with pytest.raises(AttributeError, match=msg): +- instance.node._file_id ++ instance.node.file_id_path(Path("/dicom_data")) + + + @pytest.mark.filterwarnings("ignore:The 'DicomDir'") +@@ -1651,7 +1745,7 @@ def test_clear(self, dicomdir, tdir): + assert "ISO 1" == fs.descriptor_character_set + assert [] != fs._instances + assert fs._id is not None +- assert fs._path is not None ++ assert fs.root_path is not None + uid = fs._uid + assert fs._uid is not None + assert fs._ds is not None +@@ -1662,7 +1756,7 @@ def test_clear(self, dicomdir, tdir): + fs.clear() + assert [] == fs._instances + assert fs._id is None +- assert fs._path is None ++ assert fs._root_path is None + assert uid != fs._uid + assert fs._uid.is_valid + assert fs._ds == Dataset() +@@ -2321,14 +2415,14 @@ def test_write_use_existing(self, dicomdir_copy): + tdir, ds = dicomdir_copy + assert 52 == len(ds.DirectoryRecordSequence) + fs = FileSet(ds) +- orig_paths = [p for p in fs._path.glob('**/*') if p.is_file()] ++ orig_paths = [p for p in fs.root_path.glob("**/*") if p.is_file()] + instance = fs._instances[0] + assert Path(instance.path) in orig_paths + fs.remove(instance) + orig_file_ids = [ii.ReferencedFileID for ii in fs] + fs.write(use_existing=True) + assert 50 == len(fs._ds.DirectoryRecordSequence) +- paths = [p for p in fs._path.glob('**/*') if p.is_file()] ++ paths = [p for p in fs.root_path.glob("**/*") if p.is_file()] + assert orig_file_ids == [ii.ReferencedFileID for ii in fs] + assert Path(instance.path) not in paths + assert sorted(orig_paths)[1:] == sorted(paths) +@@ -2478,6 +2572,16 @@ def setup_method(self): + def teardown_method(self): + FileSet.__len__ = self.orig + ++ @pytest.mark.skipif(platform.python_implementation() == "PyPy", ++ reason="pyfakefs does not work with generate_uid() in PyPy") ++ def test_constrained_to_fileset_root(self, fileset_fs): ++ """Ensure files cannot be copied outside the FileSet root""" ++ with pytest.raises( ++ PermissionError, ++ match=r"ReferencedFileID .* must be inside the DICOMDIR root path", ++ ): ++ FileSet(Path(FILESET_ROOT) / "DICOMDIR2") ++ + def test_copy(self, dicomdir, tdir): + """Test FileSet.copy()""" + orig_root = Path(dicomdir.filename).parent diff --git a/pydicom/debian/email-debian-med.md b/pydicom/debian/email-debian-med.md new file mode 100644 index 0000000..e01e219 --- /dev/null +++ b/pydicom/debian/email-debian-med.md @@ -0,0 +1,59 @@ + +--- + +Hi, + +After gdcm (#1153126) I looked for other Debian Med packages that read +medical image files and still have open CVEs in trixie. pydicom is one +of them, and I have an update ready if the team wants it. + +pydicom 2.4.3-2 in trixie is affected by CVE-2026-32711 (#1131492). A +crafted DICOMDIR can set Referenced File ID to a path outside of the +File-set root, and FileSet then reads, copies or moves those files. The +security tracker marks it no-dsa (minor issue). Unstable and forky are +fixed since 3.0.2-1. + +Upstream also released the fix for the 2.4 series, as 2.4.5 (commit +ed4ddea). I took the changes to fileset.py and their tests from that +commit and left out the rest (version number, CI configuration, typos +in other files). The result is 2.4.3-2+deb13u1. + +What I checked, in clean trixie containers: + +- Full build with dpkg-buildpackage. The test suite goes from 2110 + passed to 2117 passed. +- The four new tests for this issue fail against the old fileset.py and + pass with the new one. +- lintian shows nothing new. +- The patch replaces a private property of RecordNode (_file_id) with a + method (file_id_path). None of the packages in trixie that depend on + python3-pydicom use it: heudiconv, python3-dcmstack, + python3-dicompylercore, python3-guiqwt and python3-nibabel. + +One thing for you to decide: the new tests use pyfakefs, so the update +adds python3-pyfakefs to Build-Depends. Trixie has 5.8.0-1 +and the tests pass with it. If you would rather not add a build +dependency in a stable update, I can leave those tests out of the patch. + +Would it be all right if I file the trixie-pu request for this? As with +gdcm, I would need a sponsor for the upload. The debdiff is attached +(601 lines, most of them tests). + +I also have an update for invesalius in trixie (CVE-2024-42845 and +CVE-2024-44825). The second one is still open in unstable, so I replied +in #1136204 first, with a patch and test results. + +Bookworm (2.3.1-1) is affected as well. I have not looked at it yet. + +I am not subscribed to the list, so please keep me in Cc. + +Thanks, +Valentín Torassa diff --git a/pydicom/debian/pydicom_2.4.3-2+deb13u1_trixie.debdiff b/pydicom/debian/pydicom_2.4.3-2+deb13u1_trixie.debdiff new file mode 100644 index 0000000..da18eaa --- /dev/null +++ b/pydicom/debian/pydicom_2.4.3-2+deb13u1_trixie.debdiff @@ -0,0 +1,601 @@ +diff -Nru pydicom-2.4.3/debian/changelog pydicom-2.4.3/debian/changelog +--- pydicom-2.4.3/debian/changelog 2025-04-14 21:30:28.000000000 +0000 ++++ pydicom-2.4.3/debian/changelog 2026-11-10 14:47:48.000000000 +0000 +@@ -1,3 +1,14 @@ ++pydicom (2.4.3-2+deb13u1) trixie; urgency=medium ++ ++ * Team upload. ++ * CVE-2026-32711.patch: reject Referenced File IDs in a DICOMDIR that ++ point outside of the File-set root. Upstream's fix for the 2.4 series, ++ released as 2.4.5 (CVE-2026-32711, Closes: #1131492). ++ * d/control: build-depend on python3-pyfakefs, which the tests added by ++ that patch need. ++ ++ -- Valentín Torassa Tue, 10 Nov 2026 11:50:00 -0300 ++ + pydicom (2.4.3-2) unstable; urgency=medium + + * Team upload. +diff -Nru pydicom-2.4.3/debian/control pydicom-2.4.3/debian/control +--- pydicom-2.4.3/debian/control 2025-04-14 21:30:28.000000000 +0000 ++++ pydicom-2.4.3/debian/control 2026-11-10 14:36:37.000000000 +0000 +@@ -9,6 +9,7 @@ + dh-python, + python3-all, + python3-pytest, ++ python3-pyfakefs , + python3-setuptools, + python3-setuptools-scm, + python3-numpy, +diff -Nru pydicom-2.4.3/debian/patches/CVE-2026-32711.patch pydicom-2.4.3/debian/patches/CVE-2026-32711.patch +--- pydicom-2.4.3/debian/patches/CVE-2026-32711.patch 1970-01-01 00:00:00.000000000 +0000 ++++ pydicom-2.4.3/debian/patches/CVE-2026-32711.patch 2026-11-10 14:33:25.000000000 +0000 +@@ -0,0 +1,560 @@ ++Description: Reject Referenced File IDs that point outside of the File-set root ++ A crafted DICOMDIR could set ReferencedFileID to a path outside of the ++ File-set root. pydicom only checked that the path existed and then used it ++ in FileSet.copy(), FileSet.write() and when reading the instances, so files ++ outside of the File-set could be read, copied and, in some flows, moved or ++ deleted (CVE-2026-32711). ++ . ++ This is the fix that upstream cherry-picked to the 2.4 series for 2.4.5: ++ the changes to pydicom/fileset.py and their tests. The rest of that commit ++ (version number, CI configuration, typos in other files) is not included. ++Author: Darcy Mason ++Origin: upstream, https://github.com/pydicom/pydicom/commit/ed4ddeac21de09101ee0732a0a2168dd73491370 ++Bug: https://github.com/pydicom/pydicom/security/advisories/GHSA-v856-2rf8-9f28 ++Bug-Debian: https://bugs.debian.org/1131492 ++Last-Update: 2026-11-10 ++--- ++This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ ++diff --git a/pydicom/fileset.py b/pydicom/fileset.py ++index 5549d6dd86..f4412a4dcf 100644 ++--- a/pydicom/fileset.py +++++ b/pydicom/fileset.py ++@@ -344,24 +344,47 @@ def _encode_record(self, force_implicit: bool = False) -> int: ++ ++ return len(fp.getvalue()) ++ ++- @property ++- def _file_id(self) -> Optional[Path]: +++ def file_id_path(self, root_path: Path) -> Path | None: ++ """Return the *Referenced File ID* as a :class:`~pathlib.Path`. ++ +++ Params +++ ------ +++ root_path : Path +++ The root path of the parent file set. +++ ++ Returns ++ ------- ++ pathlib.Path or None ++ The *Referenced File ID* from the directory record as a ++ :class:`pathlib.Path` or ``None`` if the element value is null. +++ +++ Raises +++ ------ +++ PermissionError +++ If the file ID points to a path outside the fileset root path. +++ +++ AttributeError +++ If the Referenced File ID is missing in the directory record. +++ +++ :meta private: ++ """ ++ if "ReferencedFileID" in self._record: ++ elem = self._record["ReferencedFileID"] +++ if elem.VM < 1: +++ return None ++ if elem.VM == 1: ++- return Path(cast(str, self._record.ReferencedFileID)) ++- if elem.VM > 1: ++- return Path(*cast(List[str], self._record.ReferencedFileID)) ++- ++- return None +++ path = Path(cast(str, self._record.ReferencedFileID)) +++ else: +++ path = Path(*cast(list[str], self._record.ReferencedFileID)) +++ +++ if path is not None: +++ if path.anchor or not ( +++ (root_path / path).resolve().is_relative_to(root_path) +++ ): +++ raise PermissionError( +++ f"ReferencedFileID ('{path}') must be inside the DICOMDIR root path" +++ ) +++ return path ++ ++ raise AttributeError("No 'Referenced File ID' in the directory record") ++ ++@@ -371,7 +394,7 @@ def file_set(self) -> "FileSet": ++ return self.root.file_set ++ ++ def __getitem__(self, key: Union[str, "RecordNode"]) -> "RecordNode": ++- """Return the current node's child using it's +++ """Return the current node's child using its ++ :attr:`~pydicom.fileset.RecordNode.key` ++ """ ++ if isinstance(key, RecordNode): ++@@ -524,8 +547,8 @@ def leaf_summary(node: "RecordNode", indent_char: str) -> List[str]: ++ for node in self: ++ indent = indent_char * node.depth ++ if node.children: ++- s.append(f"{indent}{str(node)}") ++- # Summarise any leaves at the next level +++ s.append(f"{indent}{node}") +++ # Summarize any leaves at the next level ++ for child in node.children: ++ if child.has_instance: ++ s.extend(leaf_summary(child, indent_char)) ++@@ -931,9 +954,8 @@ def path(self) -> str: ++ return os.fspath(cast(Path, self._stage_path)) ++ ++ # If not staged for addition then File Set must exist on file system ++- return os.fspath( ++- cast(Path, self.file_set.path) / cast(Path, self.node._file_id) ++- ) +++ root_path = self.file_set.root_path +++ return os.fspath(root_path / cast(Path, self.node.file_id_path(root_path))) ++ ++ @property ++ def SOPClassUID(self) -> UID: ++@@ -966,7 +988,7 @@ def __init__(self, ds: Optional[DSPathType] = None) -> None: ++ to the DICOMDIR file. ++ """ ++ # The nominal path to the root of the File-set ++- self._path: Optional[Path] = None +++ self._root_path: Path | None = None ++ # The root node of the record tree used to fill out the DICOMDIR's ++ # *Directory Record Sequence*. ++ # The tree for instances currently in the File-set ++@@ -1212,7 +1234,7 @@ def clear(self) -> None: ++ """Clear the File-set.""" ++ self._tree.children = [] ++ self._instances = [] ++- self._path = None +++ self._root_path = None ++ self._ds = Dataset() ++ self._id = None ++ self._uid = generate_uid() ++@@ -1661,7 +1683,7 @@ def load( ++ ) ++ ++ try: ++- path = Path(cast(str, ds.filename)).resolve(strict=True) +++ path = Path(ds.filename).resolve(strict=True) ++ except FileNotFoundError: ++ raise FileNotFoundError( ++ "Unable to load the File-set as the 'filename' attribute " ++@@ -1692,7 +1714,7 @@ def load( ++ Optional[str], ++ ds.get("SpecificCharacterSetOfFileSetDescriptorFile", None) ++ ) ++- self._path = path.parent +++ self._root_path = path.parent ++ self._ds = ds ++ ++ # Create the record tree ++@@ -1701,20 +1723,17 @@ def load( ++ bad_instances = [] ++ for instance in self: ++ # Check that the referenced file exists ++- file_id = instance.node._file_id ++- if file_id is None: ++- bad_instances.append(instance) ++- continue ++- +++ file_id = self._file_id_path(instance.node) +++ assert file_id is not None ++ try: ++ # self.path is already set at this point ++- (cast(Path, self.path) / file_id).resolve(strict=True) +++ (self.root_path / file_id).resolve(strict=True) ++ except FileNotFoundError: ++ bad_instances.append(instance) ++ warnings.warn( ++ "The referenced SOP Instance for the directory record at " ++ f"offset {instance.node._offset} does not exist: " ++- f"{cast(Path, self.path) / file_id}" +++ f"{self.root_path / file_id}" ++ ) ++ continue ++ ++@@ -1726,6 +1745,31 @@ def load( ++ for instance in bad_instances: ++ self._instances.remove(instance) ++ +++ def _file_id_path(self, node: RecordNode) -> Path | None: +++ """Return the *Referenced File ID* from the given node +++ as a :class:`~pathlib.Path`. +++ +++ Parameters +++ ---------- +++ node: RecordNode +++ The node where the *Referenced File ID* resides. +++ +++ Returns +++ ------- +++ pathlib.Path or None +++ The *Referenced File ID* from the directory record as a +++ :class:`pathlib.Path` or ``None`` if the element value is null. +++ +++ Raises +++ ------ +++ PermissionError +++ If the file ID points to a path outside the fileset root path. +++ +++ AttributeError +++ If the Referenced File ID is missing in the directory record. +++ """ +++ return node.file_id_path(self.root_path) +++ ++ def _parse_records( ++ self, ++ ds: Dataset, ++@@ -1782,7 +1826,10 @@ def recurse_node(node: RecordNode) -> None: ++ del node.parent[node] ++ ++ # The leaf node references the FileInstance ++- if "ReferencedFileID" in node._record: +++ if ( +++ "ReferencedFileID" in node._record +++ and self._file_id_path(node) is not None +++ ): ++ node.instance = FileInstance(node) ++ self._instances.append(node.instance) ++ ++@@ -1817,12 +1864,11 @@ def recurse_node(node: RecordNode) -> None: ++ for node in missing: ++ # Get the path to the orphaned instance ++ original_value = node._record.ReferencedFileID ++- file_id = node._file_id ++- if file_id is None: +++ if (file_id := self._file_id_path(node)) is None: ++ continue ++ ++ # self.path is set for an existing File Set ++- path = cast(Path, self.path) / file_id +++ path = self.root_path / file_id ++ if node.record_type == "PRIVATE": ++ instance = self.add_custom(path, node) ++ else: ++@@ -1832,14 +1878,29 @@ def recurse_node(node: RecordNode) -> None: ++ instance.node._record.ReferencedFileID = original_value ++ ++ @property ++- def path(self) -> Optional[str]: +++ def root_path(self) -> Path: +++ """Return the absolute path to the File-set root directory as +++ :class:`pathlib.Path`. +++ +++ Raises +++ ------ +++ AttributeError +++ If the root path is not set. +++ """ +++ if self._root_path is None: +++ raise AttributeError("No root path set in the File-set") +++ +++ return self._root_path +++ +++ @property +++ def path(self) -> str | None: ++ """Return the absolute path to the File-set root directory as ++ :class:`str` (if set) or ``None`` otherwise. ++ """ ++- if self._path is not None: ++- return os.fspath(self._path) +++ if self._root_path is not None: +++ return os.fspath(self._root_path) ++ ++- return self._path +++ return None ++ ++ def _recordify(self, ds: Dataset) -> Iterator[Dataset]: ++ """Yield directory records for a SOP Instance. ++@@ -2105,16 +2166,17 @@ def write( ++ ) ++ ++ if path: ++- self._path = Path(path) +++ self._root_path = Path(path) ++ ++ # Don't write unless changed or new ++ if not self.is_staged: ++ return ++ ++ # Path to the DICOMDIR file ++- p = cast(Path, self._path) / 'DICOMDIR' +++ root = self.root_path +++ p = root / "DICOMDIR" ++ ++- # Re-use the existing directory structure if only moves or removals +++ # Reuse the existing directory structure if only moves or removals ++ # are required and `use_existing` is True ++ major_change = bool(self._stage['+']) ++ if use_existing and major_change: ++@@ -2159,26 +2221,30 @@ def write( ++ # and copy any to the stage ++ fout = {Path(ii.FileID) for ii in self} ++ fin = { ++- ii.node._file_id for ii in self ++- if ii.SOPInstanceUID not in self._stage['+'] +++ self._file_id_path(ii.node) +++ for ii in self +++ if ii.SOPInstanceUID not in self._stage["+"] ++ } ++ collisions = fout & fin ++- for instance in [ii for ii in self if ii.node._file_id in collisions]: ++- self._stage['+'][instance.SOPInstanceUID] = instance ++- instance._apply_stage('+') +++ for instance in [ +++ ii for ii in self if self._file_id_path(ii.node) in collisions +++ ]: +++ self._stage["+"][instance.SOPInstanceUID] = instance +++ instance._apply_stage("+") ++ shutil.copyfile( ++- self._path / instance.node._file_id, instance.path +++ root / cast(Path, self._file_id_path(instance.node)), +++ instance.path, ++ ) ++ ++ for instance in self: ++- dst = self._path / instance.FileID +++ dst = root / instance.FileID ++ dst.parent.mkdir(parents=True, exist_ok=True) ++ fn: Callable ++ if instance.SOPInstanceUID in self._stage['+']: ++ src = instance.path ++ fn = shutil.copyfile ++ else: ++- src = self._path / instance.node._file_id +++ src = root / cast(Path, self._file_id_path(instance.node)) ++ fn = shutil.move ++ ++ fn(os.fspath(src), os.fspath(dst)) ++diff --git a/pydicom/tests/conftest.py b/pydicom/tests/conftest.py ++index 10d1dc3950..301fd009dc 100644 ++--- a/pydicom/tests/conftest.py +++++ b/pydicom/tests/conftest.py ++@@ -22,6 +22,14 @@ def allow_reading_invalid_values(): ++ config.settings.reading_validation_mode = value ++ ++ +++@pytest.fixture +++def ignore_reading_invalid_values(): +++ value = config.settings.reading_validation_mode +++ config.settings.reading_validation_mode = config.IGNORE +++ yield +++ config.settings.reading_validation_mode = value +++ +++ ++ @pytest.fixture ++ def enforce_writing_invalid_values(): ++ value = config.settings.writing_validation_mode ++diff --git a/pydicom/tests/test_fileset.py b/pydicom/tests/test_fileset.py ++index 40bd9d833c..8ded8862da 100644 ++--- a/pydicom/tests/test_fileset.py +++++ b/pydicom/tests/test_fileset.py ++@@ -1,5 +1,6 @@ ++ ++ import os +++import platform ++ import sys ++ from pathlib import Path ++ import shutil ++@@ -10,7 +11,7 @@ ++ from pydicom import config, dcmread ++ from pydicom.data import get_testdata_file ++ from pydicom.dataset import Dataset, FileMetaDataset ++-from pydicom.filebase import DicomBytesIO +++from pydicom.filebase import DicomBytesIO, DicomFileLike ++ from pydicom.fileset import ( ++ FileSet, FileInstance, RecordNode, is_conformant_file_id, ++ generate_filename, _define_patient, _define_study, _define_series, ++@@ -81,6 +82,56 @@ def tdir(): ++ return TemporaryDirectory() ++ ++ +++FILESET_ROOT = "/path/to/fileset/" +++ABS_FILE_PATH = "/secret.txt" +++SYMLINK_TO_ABS_FILE = "Pat1/St1/Im2" +++SYMLINK_TO_ABS_DIR = "Pat1/St2" +++DOT_DOT_FILE = "../goback.txt" +++ABS_FILE_CONTENTS = "Top Secret file contents" +++COPY_PATH = "/path/to/copied/" +++ +++ +++@pytest.fixture( +++ params=[ +++ ABS_FILE_PATH, +++ DOT_DOT_FILE, +++ SYMLINK_TO_ABS_FILE, +++ SYMLINK_TO_ABS_DIR + ABS_FILE_PATH, +++ ] +++) +++def fileset_fs(request, fs, ignore_reading_invalid_values): +++ """Create an in-memory file system with pyfakefs and test DICOMDIRs""" +++ # Simplified version of submitted report from JeongAhn Jang, in pyfakefs +++ orig_dicomdir_root = Path(TEST_FILE).parent +++ dicomdir_root = Path(FILESET_ROOT) +++ fs.add_real_file( +++ orig_dicomdir_root / "77654033/CR1/6154", +++ target_path=dicomdir_root / "Pat1/St1/Im1", +++ ) +++ fs.create_file(ABS_FILE_PATH, contents=ABS_FILE_CONTENTS) +++ fs.create_dir(COPY_PATH) +++ fs.create_symlink(dicomdir_root / SYMLINK_TO_ABS_FILE, ABS_FILE_PATH) +++ fs.create_symlink(dicomdir_root / SYMLINK_TO_ABS_DIR, "/") +++ # MAKE DICOMDIR for this simplified file-set +++ fset = FileSet() +++ fset.add(dicomdir_root / "Pat1/St1/Im1") +++ fset.write(dicomdir_root) +++ +++ # Create bad DICOMDIR2 file from the simplified one +++ # Modify first referenced file +++ fset = FileSet(dicomdir_root / "DICOMDIR") +++ record = next( +++ rec for rec in fset._ds.DirectoryRecordSequence if "ReferencedFileID" in rec +++ ) +++ record.ReferencedFileID = request.param +++ +++ # Write modified DICOMDIR file +++ with open(dicomdir_root / "DICOMDIR2", "wb") as fp: +++ fset._write_dicomdir(DicomFileLike(fp)) +++ +++ yield fs +++ +++ ++ @pytest.fixture ++ def custom_leaf(): ++ """Return the leaf node from a custom 4-level record hierarchy""" ++@@ -116,7 +167,7 @@ def custom_leaf(): ++ ++ ++ @pytest.fixture ++-def private(dicomdir): +++def private(dicomdir, request, ignore_reading_invalid_values): ++ """Return a DICOMDIR dataset with PRIVATE records.""" ++ def write_record(ds): ++ """Return `ds` as explicit little encoded bytes.""" ++@@ -143,9 +194,17 @@ def private_record(): ++ middle = private_record() ++ bottom = private_record() ++ bottom.ReferencedSOPClassUIDInFile = "1.2.3.4" ++- bottom.ReferencedFileID = [ ++- "TINY_ALPHA", "PT000000", "ST000000", "SE000000", "IM000000" ++- ] +++ if hasattr(request, "param"): +++ file_ids = request.param +++ else: +++ file_ids = [ +++ "TINY_ALPHA", +++ "PT000000", +++ "ST000000", +++ "SE000000", +++ "IM000000", +++ ] +++ bottom.ReferencedFileID = file_ids ++ bottom.ReferencedSOPInstanceUIDInFile = ( ++ "1.2.276.0.7230010.3.1.4.0.31906.1359940846.78187" ++ ) ++@@ -647,6 +706,15 @@ def test_key_raises(self, dummy): ++ with pytest.raises(AttributeError, match=msg): ++ instance.node.key ++ +++ @pytest.mark.parametrize("private", [["/", "etc", "passwd"]], indirect=True) +++ def test_id_outside_root(self, private): +++ """File ID points to a path outside the root directory.""" +++ with pytest.raises( +++ PermissionError, +++ match=r"ReferencedFileID .* must be inside the DICOMDIR root path", +++ ): +++ FileSet(private) +++ ++ def test_bad_record(self, private): ++ """Test a bad directory record raises an exception when loading.""" ++ del private.DirectoryRecordSequence[0].PatientID ++@@ -709,7 +777,33 @@ def test_file_id_singleton(self, ct, tdir): ++ item.ReferencedFileID = "01" ++ ds.save_as(p / "DICOMDIR") ++ fs = FileSet(ds) ++- assert fs._instances[0].node._file_id == Path("01") +++ assert fs._instances[0].node.file_id_path(fs.root_path) == Path("01") +++ +++ def test_absolute_file_id(self, ct, tdir, ignore_reading_invalid_values): +++ """Test a singleton File ID.""" +++ fs = FileSet() +++ p = Path(tdir.name) +++ ct.save_as(p / "01") +++ fs.add(p / "01") +++ fs.write(p) +++ ds = dcmread(p / "DICOMDIR") +++ item = ds.DirectoryRecordSequence[-1] +++ item.ReferencedFileID = "/01" +++ ds.save_as(p / "DICOMDIR") +++ with pytest.raises( +++ PermissionError, +++ match=r"ReferencedFileID .* must be inside the DICOMDIR root path", +++ ): +++ FileSet(ds) +++ +++ def test_root_path_missing(self, ct): +++ """Test RecordNode._file_id if no Referenced File ID.""" +++ fs = FileSet() +++ instance = fs.add(ct) +++ # del instance.node._record.ReferencedFileID +++ msg = r"No root path set in the File-set" +++ with pytest.raises(AttributeError, match=msg): +++ fs.root_path ++ ++ def test_file_id_missing(self, ct): ++ """Test RecordNode._file_id if no Referenced File ID.""" ++@@ -718,7 +812,7 @@ def test_file_id_missing(self, ct): ++ del instance.node._record.ReferencedFileID ++ msg = r"No 'Referenced File ID' in the directory record" ++ with pytest.raises(AttributeError, match=msg): ++- instance.node._file_id +++ instance.node.file_id_path(Path("/dicom_data")) ++ ++ ++ @pytest.mark.filterwarnings("ignore:The 'DicomDir'") ++@@ -1651,7 +1745,7 @@ def test_clear(self, dicomdir, tdir): ++ assert "ISO 1" == fs.descriptor_character_set ++ assert [] != fs._instances ++ assert fs._id is not None ++- assert fs._path is not None +++ assert fs.root_path is not None ++ uid = fs._uid ++ assert fs._uid is not None ++ assert fs._ds is not None ++@@ -1662,7 +1756,7 @@ def test_clear(self, dicomdir, tdir): ++ fs.clear() ++ assert [] == fs._instances ++ assert fs._id is None ++- assert fs._path is None +++ assert fs._root_path is None ++ assert uid != fs._uid ++ assert fs._uid.is_valid ++ assert fs._ds == Dataset() ++@@ -2321,14 +2415,14 @@ def test_write_use_existing(self, dicomdir_copy): ++ tdir, ds = dicomdir_copy ++ assert 52 == len(ds.DirectoryRecordSequence) ++ fs = FileSet(ds) ++- orig_paths = [p for p in fs._path.glob('**/*') if p.is_file()] +++ orig_paths = [p for p in fs.root_path.glob("**/*") if p.is_file()] ++ instance = fs._instances[0] ++ assert Path(instance.path) in orig_paths ++ fs.remove(instance) ++ orig_file_ids = [ii.ReferencedFileID for ii in fs] ++ fs.write(use_existing=True) ++ assert 50 == len(fs._ds.DirectoryRecordSequence) ++- paths = [p for p in fs._path.glob('**/*') if p.is_file()] +++ paths = [p for p in fs.root_path.glob("**/*") if p.is_file()] ++ assert orig_file_ids == [ii.ReferencedFileID for ii in fs] ++ assert Path(instance.path) not in paths ++ assert sorted(orig_paths)[1:] == sorted(paths) ++@@ -2478,6 +2572,16 @@ def setup_method(self): ++ def teardown_method(self): ++ FileSet.__len__ = self.orig ++ +++ @pytest.mark.skipif(platform.python_implementation() == "PyPy", +++ reason="pyfakefs does not work with generate_uid() in PyPy") +++ def test_constrained_to_fileset_root(self, fileset_fs): +++ """Ensure files cannot be copied outside the FileSet root""" +++ with pytest.raises( +++ PermissionError, +++ match=r"ReferencedFileID .* must be inside the DICOMDIR root path", +++ ): +++ FileSet(Path(FILESET_ROOT) / "DICOMDIR2") +++ ++ def test_copy(self, dicomdir, tdir): ++ """Test FileSet.copy()""" ++ orig_root = Path(dicomdir.filename).parent +diff -Nru pydicom-2.4.3/debian/patches/series pydicom-2.4.3/debian/patches/series +--- pydicom-2.4.3/debian/patches/series 2025-04-14 21:30:28.000000000 +0000 ++++ pydicom-2.4.3/debian/patches/series 2026-11-10 14:33:25.000000000 +0000 +@@ -3,3 +3,4 @@ + ignore_tests_with_wrong_gdcm_usage.patch + sphinx_no_git.patch + skip-i386-incapable-tests.patch ++CVE-2026-32711.patch diff --git a/pydicom/debian/trixie-pu-request.md b/pydicom/debian/trixie-pu-request.md new file mode 100644 index 0000000..5da7be1 --- /dev/null +++ b/pydicom/debian/trixie-pu-request.md @@ -0,0 +1,78 @@ + + +To: submit@bugs.debian.org +Subject: trixie-pu: package pydicom/2.4.3-2+deb13u1 + +Package: release.debian.org +Severity: normal +Tags: trixie +X-Debbugs-Cc: pydicom@packages.debian.org +Control: affects -1 + src:pydicom +User: release.debian.org@packages.debian.org +Usertags: pu + +[ Reason ] +pydicom 2.4.3-2 in trixie is affected by CVE-2026-32711 (#1131492), which +is fixed in unstable since 3.0.2-1. The security tracker marks it +(minor issue). This update fixes it in a point release. + +[ Impact ] +pydicom.fileset.FileSet trusts the Referenced File ID values of a DICOMDIR. +A crafted DICOMDIR can point them outside of the File-set root, and an +application that loads it and then calls FileSet.copy() or FileSet.write() +reads, copies or moves files outside of that directory with the user's +permissions. + +[ Tests ] +All on amd64, in fresh debian:trixie containers updated on 2026-11-10: +- Full build with dpkg-buildpackage -us -uc. The patch applies without + fuzz. +- Upstream test suite at build time: 2110 passed with 2.4.3-2 and 2117 + passed with this update. The seven additional tests come with the + patch. +- The four new tests that cover this issue fail against the fileset.py of + 2.4.3-2 and pass with this update. +- lintian: no new tags compared with 2.4.3-2. +- Reverse dependencies in trixie (heudiconv, python3-dcmstack, + python3-dicompylercore, python3-guiqwt, python3-nibabel): none of them + uses RecordNode._file_id, the private property that the patch replaces. + +[ Risks ] +Low. The patch is upstream's own fix for the 2.4 series (commit ed4ddea, +released as 2.4.5), limited to pydicom/fileset.py and its tests. It adds +a check that every Referenced File ID is relative and resolves inside of +the File-set root, and raises PermissionError otherwise. A DICOMDIR that +refers to files outside of its own directory is rejected from now on, +which is the intended change. One private property, RecordNode._file_id, becomes the +method RecordNode.file_id_path(). + +The new tests need pyfakefs, so python3-pyfakefs is added to +Build-Depends. Trixie has 5.8.0-1 and the tests pass with it. + +[ Checklist ] + [x] *all* changes are documented in the d/changelog + [ ] I reviewed all changes and I approve them + [x] attach debdiff against the package in (old)stable + [x] the issue is verified as fixed in unstable + +[ Changes ] + * CVE-2026-32711.patch (upstream ed4ddea): reject Referenced File IDs + that point outside of the File-set root when a DICOMDIR is loaded, + copied or written. + * debian/control: add python3-pyfakefs to Build-Depends for + the tests added by that patch. + * debian/patches/series and debian/changelog updated accordingly. + +[ Other info ] +I am not a Debian member, so the upload will need a sponsor from the +Debian Med team.