Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a cram decode hang from block_resize. #1680

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

jkbonfield
Copy link
Contributor

46bcc36 changed the memory block realloc from growing by size1.5 to size1.25, but neither are correct when the original size is very small. Specifically the hts-specs test/cram/3.0/passed/1002_qual.cram file calls block_resize with b->alloc=2. Doing *1.25 on this gives us 2 still due to integer rounding, and so an infinite loop occurs.

It never assumed we'd start with such a small block and it attempts to leap from size 0 to size 1024, but obviously allocating its own blocks to exact sizes and bypassing this initial block growth check.

Refactored the code so to remove the loop, remove the ?: for size 0, and generally just smarten it up a bit.

Tested on Illumina, Ultima Genomics and Oxford Nanopore files and it's no worse on speed / memory to before, and sometimes 2-3% quicker or smaller.

Bug reported by Sebastian Deorowicz

46bcc36 changed the memory block realloc from growing by size*1.5 to
size*1.25, but neither are correct when the original size is very
small.  Specifically the hts-specs test/cram/3.0/passed/1002_qual.cram
file calls block_resize with b->alloc=2.  Doing *1.25 on this gives us
2 still due to integer rounding, and so an infinite loop occurs.

It never assumed we'd start with such a small block and it attempts to
leap from size 0 to size 1024, but obviously allocating its own blocks
to exact sizes and bypassing this initial block growth check.

Refactored the code so to remove the loop, remove the ?: for size 0,
and generally just smarten it up a bit.

Tested on Illumina, Ultima Genomics and Oxford Nanopore files and it's
no worse on speed / memory to before, and sometimes 2-3% quicker or
smaller.

Bug reported by Sebastian Deorowicz
@whitwham whitwham merged commit 35dd2d0 into samtools:develop Oct 4, 2023
8 checks passed
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