Skip to content

Conversation

@wegank
Copy link
Contributor

@wegank wegank commented Dec 13, 2025

When computing Gröbner basis with respect to an elimination ordering, leadmons[0] is initialized as an array of size num_gb[0] * (bht->nv - st->nev).

/* Leading monomials from Grobner basis */
int32_t *bexp_lm = get_lm_from_bs(bs, bht);
leadmons[0] = bexp_lm;
int32_t len = bs->lml;
num_gb[0] = compute_num_gb(bexp_lm, len, bht->nv, st->nev);
int32_t *bexp_lm2 = NULL;
if(st->nev){
bexp_lm2 = calloc(num_gb[0]*(bht->nv - st->nev), sizeof(int32_t));
for(int32_t i = 0; i < num_gb[0]; i++){
for(int j = 0; j < bht->nv - st->nev; j++){
bexp_lm2[i*(bht->nv - st->nev) + j] = bexp_lm[i*bht->nv + st->nev + j];
}
}
leadmons[0] = bexp_lm2;
}

However, duplicate_data_mthread_trace supposes that leadmons[0] is of size num_gb[0] * (st->nvars).

const long len = num_gb[0] * (st->nvars);

This causes undefined behavior on Line 162 below. On one of my machines, the line causes segmentation fault on input_files/henrion5-qq.ms for j between the two values, with a probability of about 5%.

/* leadmons_ori[0] has already been allocated*/
for(int i = 1; i < nthreads; i++){
leadmons_ori[i] = (int32_t *)calloc(len, sizeof(int32_t));
for(long j = 0; j < len; j++){
leadmons_ori[i][j] = leadmons_ori[0][j];
}
}

This PR fixes the issue on my machine.

@wegank wegank force-pushed the duplicate-data-fix branch from fd1e639 to aa1c2cf Compare December 13, 2025 01:46
@ederc ederc mentioned this pull request Dec 15, 2025
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.

1 participant