File tree 2 files changed +28
-3
lines changed
2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ static int sam_hrecs_update_hashes(sam_hrecs_t *hrecs,
145
145
const char * name = NULL ;
146
146
const char * altnames = NULL ;
147
147
hts_pos_t len = -1 ;
148
- int r ;
148
+ int r , dup = 0 ;
149
149
khint_t k ;
150
150
151
151
while (tag ) {
@@ -154,7 +154,12 @@ static int sam_hrecs_update_hashes(sam_hrecs_t *hrecs,
154
154
name = tag -> str + 3 ;
155
155
} else if (tag -> str [0 ] == 'L' && tag -> str [1 ] == 'N' ) {
156
156
assert (tag -> len >= 3 );
157
+ hts_pos_t tmp = len ;
157
158
len = strtoll (tag -> str + 3 , NULL , 10 );
159
+ if (tmp != -1 && tmp != len ) {
160
+ //LN again with different value, discard
161
+ dup = 1 ;
162
+ }
158
163
} else if (tag -> str [0 ] == 'A' && tag -> str [1 ] == 'N' ) {
159
164
assert (tag -> len >= 3 );
160
165
altnames = tag -> str + 3 ;
@@ -173,6 +178,12 @@ static int sam_hrecs_update_hashes(sam_hrecs_t *hrecs,
173
178
return -1 ; // LN should be present, according to spec.
174
179
}
175
180
181
+ if (dup ) {
182
+ hts_log_error ("Header includes @SQ line \"%s\" with duplicate LN: tag" , \
183
+ name );
184
+ return -1 ;
185
+ }
186
+
176
187
// Seen already?
177
188
k = kh_get (m_s2i , hrecs -> ref_hash , name );
178
189
if (k < kh_end (hrecs -> ref_hash )) {
Original file line number Diff line number Diff line change @@ -1911,6 +1911,12 @@ static sam_hdr_t *sam_hdr_sanitise(sam_hdr_t *h) {
1911
1911
cp [h -> l_text ] = '\0' ;
1912
1912
}
1913
1913
1914
+ if (sam_hdr_fill_hrecs (h ) < 0 ) {
1915
+ //failed in parsing / validation
1916
+ sam_hdr_destroy (h );
1917
+ return NULL ;
1918
+ }
1919
+
1914
1920
return h ;
1915
1921
}
1916
1922
@@ -1964,8 +1970,16 @@ static sam_hdr_t *sam_hdr_create(htsFile* fp) {
1964
1970
strncpy (sn , q , r - q );
1965
1971
q = r ;
1966
1972
} else {
1967
- if (strncmp (q , "LN:" , 3 ) == 0 )
1968
- ln = strtoll (q + 3 , (char * * )& q , 10 );
1973
+ if (strncmp (q , "LN:" , 3 ) == 0 ) {
1974
+ hts_pos_t tmp = strtoll (q + 3 , (char * * )& q , 10 );
1975
+ if (ln != -1 && tmp != ln ) {
1976
+ //duplicate LN tag with different value
1977
+ hts_log_error ("111Header includes @SQ line \"%s\" with \
1978
+ duplicate LN: tag" , sn );
1979
+ goto error ;
1980
+ }
1981
+ ln = tmp ;
1982
+ }
1969
1983
}
1970
1984
1971
1985
while (* q != '\t' && * q != '\n' && * q != '\0' )
You can’t perform that action at this time.
0 commit comments