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

More CRAM fuzz fixes (integer overflows) #1713

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cram/cram_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,9 @@ static inline int extend_ref(char **ref, uint32_t (**hist)[5], hts_pos_t pos,
return 0;

// realloc
if (pos - ref_start > UINT_MAX)
return -2; // protect overflow in new_end calculation

hts_pos_t old_end = *ref_end ? *ref_end : ref_start;
hts_pos_t new_end = ref_start + 1000 + (pos-ref_start)*1.5;

Expand Down
4 changes: 2 additions & 2 deletions cram/cram_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2079,10 +2079,10 @@ int cram_compress_block2(cram_fd *fd, cram_slice *s,
} else if (c) {
free(c);
} else {
sz[m] = b->uncomp_size*2+1000; // arbitrarily worse than raw
sz[m] = UINT_MAX; // arbitrarily worse than raw
}
} else {
sz[m] = b->uncomp_size*2+1000; // arbitrarily worse than raw
sz[m] = UINT_MAX; // arbitrarily worse than raw
}
}

Expand Down