Skip to content

Commit aba9dc4

Browse files
authored
Merge pull request #285 from tfenne/tf_fix_oom_from_signed_array_size_arithmetic
Fix signed integer overflow in phasing HMM array indexing
2 parents f916674 + c2a88cc commit aba9dc4

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

phase/src/models/phasing_hmm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void phasing_hmm::backward() {
220220
if (curr_segment_locus == 0) {
221221
SUMK();
222222
//phasingProb[curr_segment_index] = prob;
223-
std::copy(prob.begin(), prob.end(), phasingProb.begin()+curr_segment_index*C->n_states*HAP_NUMBER);
223+
std::copy(prob.begin(), prob.end(), phasingProb.begin()+(size_t)curr_segment_index*C->n_states*HAP_NUMBER);
224224
//phasingProbSum[curr_segment_index] = probSumH;
225225
std::copy(probSumH.begin(), probSumH.end(), phasingProbSum.begin()+curr_segment_index*HAP_NUMBER);
226226
phasingProbSumSum[curr_segment_index] = probSumT;
@@ -229,7 +229,7 @@ void phasing_hmm::backward() {
229229
//STORE PROBS FOR PHASING RARE HETS
230230
if (VAR_TYP[curr_idx_locus] == VAR_FLAT_HET) {
231231
//imputeProb[curr_missing_locus] = prob;
232-
std::copy(prob.begin(), prob.end(), imputeProb.begin()+curr_missing_locus*C->n_states*HAP_NUMBER);
232+
std::copy(prob.begin(), prob.end(), imputeProb.begin()+(size_t)curr_missing_locus*C->n_states*HAP_NUMBER);
233233
//imputeProbSum[curr_missing_locus] = probSumH;
234234
std::copy(probSumH.begin(), probSumH.end(), imputeProbSum.begin()+curr_missing_locus*HAP_NUMBER);
235235
imputeProbSumSum[curr_missing_locus] = probSumT;

phase/src/models/phasing_hmm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ void phasing_hmm::SUMK() {
289289
inline
290290
bool phasing_hmm::TRANS_HAP()
291291
{
292-
const int states_haps = C->n_states*HAP_NUMBER;
292+
const size_t states_haps = (size_t)C->n_states*HAP_NUMBER;
293293
sumHProbs = 0.0f;
294294
yt = C->getTransition(VAR_ABS[curr_idx_locus], VAR_ABS[curr_idx_locus+1]);
295295
nt = 1.0f - yt;
@@ -327,7 +327,7 @@ bool phasing_hmm::SAMPLE_DIP() {
327327
inline
328328
void phasing_hmm::IMPUTE_FLAT_HET()
329329
{
330-
const int states_haps = C->n_states*HAP_NUMBER;
330+
const size_t states_haps = (size_t)C->n_states*HAP_NUMBER;
331331
const __m256 _one = _mm256_set1_ps(1.0f);
332332
const __m256 _zero = _mm256_set1_ps(0.0f);
333333
__m256 _scaleR = _mm256_load_ps(&imputeProbSum[curr_missing_locus*HAP_NUMBER]);

0 commit comments

Comments
 (0)