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.
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.
diff --git a/src/toolkit/bamtools_filter.cpp b/src/toolkit/bamtools_filter.cpp index 16a1b0d..9c2ea44 100644