Fix @PG
linking when records make a loop
#1702
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If all the
@PG
records passed tosam_hdr_link_pg()
form a singlePP
loop, all entries in thesam_hrecs_t::pg_end
array it builds get set to -1, indicating that there are no chain start points. These entries are then removed to make the final list, but due to a bug in handling the case where there are noPP
links the number of entries was incorrectly set to 1 instead of 0. This could lead to an out-of-bounds read insam_hdr_add_pg()
when linking new@PG
entries to the existing ones.Fix by ensuring that only valid end points are returned in the
sam_hrecs_t::pg_end array
, and the length is set to zero if no ends are detected due to a loop.Adds a warning if a
@PG
record is found with a PP link to itself. Detecting longer loops is left for future work. Fixes another warning which incorrectly said 'SN' instead of 'ID' in its message.Adds an
assert()
insam_hdr_add_pg()
to catch any other cases of the out-of-bounds read.Adds tests for loopy
@PG
records.Thanks to @OctavioGalland for the bug report. Fixes #1694