SIGSEGV on threaded copy of DcmFileFormat

Bug #1487389 reported by Sjors Gielen on 2015-08-21
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dcmtk (Ubuntu)

Bug Description

When a DcmFileFormat is copied in a thread, there is a possible race condition that may lead to SIGSEGV because of a null pointer dereference.

A test case is attached. It creates an empty DcmFileFormat, then spawns 12 threads that will copy the DcmFileFormat 1000 times. In my experiments, in about 75% of the runs, it crashes with a segmentation fault with the following stack trace:

* thread #4: tid = 21848, 0x00007f7275242b33`DcmSequenceOfItems::DcmSequenceOfItems(DcmSequenceOfItems const&) + 131, name = 'testcase', stop reason = invalid address (fault address: 0x0)
  * frame #0: 0x00007f7275242b33`DcmSequenceOfItems::DcmSequenceOfItems(DcmSequenceOfItems const&) + 131
    frame #1: 0x00007f7275249441`DcmFileFormat::DcmFileFormat(DcmFileFormat const&) + 17
    frame #2: 0x00000000004014bd testcase`operator(__closure=0x0000000002150e80) + 63 at testcase.cpp:17
    frame #3: 0x00000000004018c2 testcase`_M_invoke(__functor=0x0000000002157a20) + 32 at functional:2071

The test case contains a commented out line that will lock a mutex before performing the copy; if this line is uncommented, no crashes are seen, confirming suspicions of a race condition.

I compile the test case using the following command:

  g++ -o testcase testcase.cpp -g -Wall -std=c++11 -DHAVE_CONFIG_H -ldcmdata

I'm reporting this here because I use the Ubuntu repository version of the package. If you want me to, I can report this upstream as well, after verifying that the problem is not caused by Ubuntu/Debian-specific patches.

ProblemType: Bug
DistroRelease: Ubuntu 14.04
Package: libdcmtk2 3.6.0-15
ProcVersionSignature: Ubuntu 3.13.0-61.100-generic 3.13.11-ckt22
Uname: Linux 3.13.0-61-generic x86_64
NonfreeKernelModules: nvidia
ApportVersion: 2.14.1-0ubuntu3.12
Architecture: amd64
CurrentDesktop: XFCE
Date: Fri Aug 21 11:26:49 2015
InstallationDate: Installed on 2015-02-18 (183 days ago)
InstallationMedia: Xubuntu 14.04.1 LTS "Trusty Tahr" - Release amd64 (20140723)
SourcePackage: dcmtk
UpgradeStatus: No upgrade log present (probably fresh install)

Sjors Gielen (sgielen) wrote :
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers