[med-svn] [Git][med-team/bamtools][master] Fix output data on bigendian architectures

Andreas Tille (@tille) gitlab at salsa.debian.org
Fri Jul 12 12:21:00 BST 2024



Andreas Tille pushed to branch master at Debian Med / bamtools


Commits:
f427af70 by Andreas Tille at 2024-07-12T13:20:32+02:00
Fix output data on bigendian architectures

- - - - -


5 changed files:

- debian/changelog
- + debian/patches/do_not_corrupt_output.patch
- + debian/patches/filter_script.patch
- debian/patches/series
- debian/tests/run-unit-test


Changes:

=====================================
debian/changelog
=====================================
@@ -1,3 +1,11 @@
+bamtools (2.5.2+dfsg-6) UNRELEASED; urgency=medium
+
+  * Fix output data on bigendian architectures (Thanks a lot for the
+    patch from Vladimir Petko <vladimir.petko at canonical.com>!)
+    Closes: #1075990
+
+ -- Andreas Tille <tille at debian.org>  Fri, 12 Jul 2024 13:18:51 +0200
+
 bamtools (2.5.2+dfsg-5) unstable; urgency=medium
 
   * d/control: add myself to uploaders.


=====================================
debian/patches/do_not_corrupt_output.patch
=====================================
@@ -0,0 +1,36 @@
+Description: bamtools crashes/corrupts output data on s390x
+ The issue was detected in Ubuntu autopkgtests. The call to
+ bamtools revert -in sam_spec_example.bam -out out.bam
+ fails due to the buffer overflow detected
+ This is due to the write loop in
+ src/api/internal/bam/BamWriter_p.cpp
+ using single byte instead of sizeof(uint32_t) increment to
+ swap bytes in the integer data.
+ The output file on s390x is corrupted by the write operation.
+ bamtools crash with the hardening flags enabled.
+Author: Vladimir Petko <vladimir.petko at canonical.com>
+Bug: https://github.com/pezmaster31/bamtools/issues/235
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/bamtools/+bug/2072463
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1075990
+Last-Update: 2024-07-09
+
+--- a/src/api/internal/bam/BamWriter_p.cpp
++++ b/src/api/internal/bam/BamWriter_p.cpp
+@@ -349,7 +349,7 @@
+             char* cigarData = new char[packedCigarLength]();
+             std::memcpy(cigarData, packedCigar.data(), packedCigarLength);
+             if (m_isBigEndian) {
+-                for (size_t i = 0; i < packedCigarLength; ++i) {
++                for (size_t i = 0; i < packedCigarLength; i+= sizeof(uint32_t)) {
+                     BamTools::SwapEndian_32p(&cigarData[i]);
+                 }
+             }
+@@ -501,7 +501,7 @@
+             std::memcpy(cigarData, packedCigar.data(), packedCigarLength);
+             if (m_isBigEndian) {
+                 for (size_t i = 0; i < packedCigarLength;
+-                     ++i) {  // FIXME: similarly, this should be "i += 4", not "++i"
++                     i+= sizeof(uint32_t)) {  // FIXME: similarly, this should be "i += 4", not "++i"
+                     BamTools::SwapEndian_32p(&cigarData[i]);
+                 }
+             }


=====================================
debian/patches/filter_script.patch
=====================================
@@ -0,0 +1,43 @@
+Description: fix infinite loop on s390x, arm, ppc64el
+ const std::string FilterTool::FilterToolPrivate::GetScriptContents()
+ loops indefinitely due to fgets() not setting eof flag if
+ the call returns data on those platforms.
+ The fgetc/ungetc calls then set/clear eof flag indefinitely.
+Author: Vladimir Petko <vladimir.petko at canonical.com>
+Bug: https://github.com/pezmaster31/bamtools/issues/237
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=992143
+Last-Update: 2024-07-09
+
+diff --git a/src/toolkit/bamtools_filter.cpp b/src/toolkit/bamtools_filter.cpp
+index 16a1b0d..9c2ea44 100644
+--- a/src/toolkit/bamtools_filter.cpp
++++ b/src/toolkit/bamtools_filter.cpp
+@@ -540,22 +540,18 @@ const std::string FilterTool::FilterToolPrivate::GetScriptContents()
+     // read in entire script contents
+     char buffer[1024];
+     std::ostringstream docStream;
+-    while (true) {
+-
+-        // peek ahead, make sure there is data available
+-        char ch = fgetc(inFile);
+-        ungetc(ch, inFile);
+-        if (feof(inFile)) {
++    while (!feof(inFile)) {
++        // read next block of data
++        char *data = fgets(buffer, 1024, inFile);
++        if (data == 0) {
+             break;
+         }
+-
+-        // read next block of data
+-        if (fgets(buffer, 1024, inFile) == 0) {
++        if (ferror(inFile)) {
+             std::cerr << "bamtools filter ERROR: could not read script contents" << std::endl;
+             return std::string();
+         }
+ 
+-        docStream << buffer;
++        docStream << data;
+     }
+ 
+     // close script file


=====================================
debian/patches/series
=====================================
@@ -2,3 +2,5 @@
 shared_and_static.patch
 #fix_soversion.patch
 typo.patch
+filter_script.patch
+do_not_corrupt_output.patch


=====================================
debian/tests/run-unit-test
=====================================
@@ -21,19 +21,7 @@ bamtools count -in sam_spec_example.bam
 
 bamtools coverage -in sam_spec_example.bam -out out
 
-# This test fails on ppc64el for whatever reason and is for the moment (see bug #933505)
-# The test is also problematic for armel (see bug #992143)
-ARCH=$(dpkg --print-architecture)
-if [ "$ARCH" != "ppc64el" -a "$ARCH" != "arm64" -a "$ARCH" != "armel"-a "$ARCH" != "armhf" -a "$ARCH" != "s390x"  ] ; then
-   bamtools filter -script filter_script -in sam_spec_example.bam -out out.bam
-else
-   if [ "$ARCH" = "ppc64el" ] ; then
-      echo "The following test is known to fail on ppc64el architecture (see bug #933505)"
-   else
-      echo "The following test is known to time out on $ARCH architecture (see bug #953939)"
-   fi
-   echo "bamtools filter -script filter_script -in sam_spec_example.bam -out out.bam"
-fi
+bamtools filter -script filter_script -in sam_spec_example.bam -out out.bam
 
 bamtools header -in sam_spec_example.bam
 



View it on GitLab: https://salsa.debian.org/med-team/bamtools/-/commit/f427af701144745fc2a9f74157ad81ccd44d9774

-- 
This project does not include diff previews in email notifications.
View it on GitLab: https://salsa.debian.org/med-team/bamtools/-/commit/f427af701144745fc2a9f74157ad81ccd44d9774
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20240712/132577a2/attachment-0001.htm>


More information about the debian-med-commit mailing list