Skip to content

Fix silent truncation in IteratorRowAllRefs on I/O errors#1379

Open
gileshall wants to merge 1 commit intopysam-developers:masterfrom
gileshall:fix-silent-truncation-iteratorrowallrefs
Open

Fix silent truncation in IteratorRowAllRefs on I/O errors#1379
gileshall wants to merge 1 commit intopysam-developers:masterfrom
gileshall:fix-silent-truncation-iteratorrowallrefs

Conversation

@gileshall
Copy link

Summary

IteratorRowAllRefs.__next__() (used by samfile.fetch() without a region) only checked retval > 0 to decide whether a record was available. All non-positive return values — including I/O errors (retval < -1) and truncated files (retval == -2) — were silently treated as end-of-reference, causing the iterator to advance to the next tid. On a read error mid-file, callers get StopIteration instead of an exception and have no indication that results are incomplete.

Every other iterator in pysam (IteratorRowRegion, IteratorRowAll, IteratorRowHead, IteratorRowSelection, VariantFile, etc.) already distinguishes EOF from error. IteratorRowAllRefs was the only one missing this check.

Add explicit error checks matching the pattern used by IteratorRowRegion: raise IOError on retval < -1, only treat retval == -1 as normal end-of-reference.

IteratorRowAllRefs.__next__() only checked `retval > 0` to decide
whether a record was available. All non-positive return values,
including I/O errors (retval < -1) and truncated files (retval == -2),
were silently treated as end-of-reference and the iterator advanced
to the next tid. This caused `samfile.fetch()` without a region to
silently yield truncated results on read errors with no exception.

Add explicit error checks matching the pattern already used by
IteratorRowRegion: raise IOError on retval < -1, only treat
retval == -1 as normal end-of-reference.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants