Skip to content

Commit

Permalink
fix segfault on empty SAM tag [CW-4299]
Browse files Browse the repository at this point in the history
  • Loading branch information
julibeg committed Jun 24, 2024
1 parent f4f213a commit 546536e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.18.4]
### Fixed
- Segfault on SAM-style tags without values in the FASTQ header.

## [v0.18.3]
### Fixed
- Bug causing segfault on unlikely RG SAM tags in FASTQ header comments.
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ regression_test_parse_rg_fastq: fastcat
done;
rm -r test/test-tmp


.PHONY: regression_test_parse_rg_bam
regression_test_parse_rg_bam: bamstats
if [ -d test/test-tmp ]; then rm -r test/test-tmp; fi
Expand All @@ -233,6 +232,10 @@ regression_test_parse_rd_fastq: fastcat
if [ -d test/test-tmp ]; then rm -r test/test-tmp; fi
mkdir test/test-tmp && \
cd test/test-tmp && \
../../fastcat ../parse_rd/RD-first-tag-and-no-RG.fastq -i rd > /dev/null && \
grep -q dummy_run_id rd
for i in ../parse_rd/*.fastq; do \
echo $$i; \
../../fastcat $$i --histograms hist -i rd > /dev/null; \
diff rd $$i.runids; \
rm -rf hist rg; \
done;
rm -r test/test-tmp
5 changes: 4 additions & 1 deletion src/fastqcomments.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ read_meta parse_read_meta(kstring_t comment) {
key = strtok_r(pch, ":", &p2);
keytype = strtok_r(NULL, ":", &p2);
value = strtok_r(NULL, "", &p2);
// we allow empty tags (e.g. 'RG:Z:'); in this case, `keytype` will be
// non-null, but `value` will be null; we set it to ""
if (keytype != NULL && value == NULL) value = "";
}
else {
// split words on `=`
Expand All @@ -96,7 +99,7 @@ read_meta parse_read_meta(kstring_t comment) {
}

// if there was no delimiter in the word, value will be NULL --> add word to `rest`
if (value == NULL && !sam_tags) {
if (value == NULL) {
ksprintf_with_opt_delim(meta->rest, " ", "%s", key);
} else {
if (!strcmp(key, "runid") || !strcmp(key, "RD")) {
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

const char *argp_program_version = "0.18.3";
const char *argp_program_version = "0.18.4";
File renamed without changes.
2 changes: 2 additions & 0 deletions test/parse_rd/RD-first-tag-and-no-RG-CW-4285.fastq.runids
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
filename run_id count
../parse_rd/RD-first-tag-and-no-RG-CW-4285.fastq dummy_run_id 1
4 changes: 4 additions & 0 deletions test/parse_rd/empty-RD-CW-4299.fastq
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@9ae4818c-61e9-4011-bf40-ca5721922da4 RD:Z:
AAAAAAAAAAAAAAAAAA
+
AAAAAAAAAAAAAAAAAA
2 changes: 2 additions & 0 deletions test/parse_rd/empty-RD-CW-4299.fastq.runids
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
filename run_id count
../parse_rd/empty-RD-CW-4299.fastq 1

0 comments on commit 546536e

Please sign in to comment.