Skip to content

Commit f90cbad

Browse files
Fixing a big that bypassed a range check on mapq values when reading SAM records
1 parent 6547c76 commit f90cbad

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sam_record.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ sam_rec::sam_rec(const string &line) {
112112
istringstream iss; // ADS: change to set the buffer from "line"
113113
iss.rdbuf()->pubsetbuf(const_cast<char*>(line.c_str()), line.size());*/
114114
istringstream iss(line); // ADS: unfortunate macos stuff?
115-
uint32_t will_become_mapq = 0; // to not read mapq as character
116-
// since it's uint8_t
115+
int32_t will_become_mapq = 0; // to not read mapq as character
116+
// since it's uint8_t
117117
if (!(iss >>
118118
qname >> flags >> rname >> pos >> will_become_mapq >>
119119
cigar >> rnext >> pnext >> tlen >> seq >> qual))
120120
throw runtime_error("incorrect SAM record:\n" + line);
121-
if (mapq > 255)
121+
if (will_become_mapq < 0 || will_become_mapq > 255)
122122
throw runtime_error("invalid mapq in SAM record: " + line);
123123
mapq = static_cast<uint8_t>(will_become_mapq);
124124

0 commit comments

Comments
 (0)