[MOAB-dev] compute_partition_sqij corruption

Michel de Messieres demessie at txcorp.com
Tue Jan 15 13:57:50 CST 2019


hi,

I am seeing a corrupt memory read for: moab::ScdInterface::compute_partition_sqij

The issue is these lines:
    double ijratio = ((double)(gijk[3]-gijk[0]))/((double)(gijk[4]-gijk[1]));
    
    unsigned int ind = std::lower_bound(ppfactors.begin(), ppfactors.end(), ijratio) - ppfactors.begin();
    if (ind && fabs(ppfactors[ind-1]-ijratio) < fabs(ppfactors[ind]-ijratio)) ind--;

If std::lower_bound returns ppfactors.end() for finding no match, then ind will be out of bounds.
Then ppfactors[ind] reads bad memory.

I attached a test to demonstrate this (test.cpp).

Even though the bad memory read always happens the code will coincidentally work out.
It may not fail until after several thousand runs.

I attached a batch script I use to detect this (run.sh).

I can’t see how ijratio is guaranteed to be below or equal one of the factors so perhaps we are not setting this up correctly.
Clamping ind resolves the issue for me but I’m not sure what the complete solution is here.

Thanks,
Michel




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/moab-dev/attachments/20190115/a511602f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: run.sh
Type: application/octet-stream
Size: 428 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/moab-dev/attachments/20190115/a511602f/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/moab-dev/attachments/20190115/a511602f/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cpp
Type: application/octet-stream
Size: 1201 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/moab-dev/attachments/20190115/a511602f/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/moab-dev/attachments/20190115/a511602f/attachment-0002.html>


More information about the moab-dev mailing list