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

libnclist: find_suboverlap_start doesn't check isub against nlists, can segfault #133

Open
GoogleCodeExporter opened this issue Apr 8, 2016 · 1 comment

Comments

@GoogleCodeExporter
Copy link

Using libnclist from pygr 0.8.2, the find_suboverlap_start function used by 
find_intervals can cause a segfault. This can happen at least when there are no 
SublistHeaders, maybe otherwise as well; I'm not sure. The following simple C 
code demonstrates the issue:

=====
#define BUILD_C_LIBRARY
#include "intervaldb.h"
int main() {
    const int n = 4;
    IntervalMap im[n];
    unsigned i;

    for (i = 0; i < 4; ++i) {
        im[i].start = i;
        im[i].end = 2*(i+1);
        im[i].target_id = 0;
    }

    int ntop, nlists;
    SublistHeader *subheader = build_nested_list_inplace(im, 4, &ntop, &nlists);

    IntervalIterator *ito = interval_iterator_alloc();

    IntervalMap buf[1];
    for (IntervalIterator *it = ito; it;) {
        int found;
        find_intervals(it, 0, 8, im, n, subheader, nlists, buf, 1, &found, &it);
        if (found == 1)
            printf("Found overlap: %d %d\n", buf[0].start, buf[0].end);
    }

    free_interval_iterator(ito);
}
=====

When run, this code segfaults, since nlists is 0 and thus subheader is an empty 
array and find_overlap_start accesses the invalid pointer subheader[0].

To fix, add a check that "isub < nlists" in the first if statement in 
find_overlap_start.

Original issue reported on code.google.com by Deewi...@gmail.com on 8 Jun 2011 at 1:27

@GoogleCodeExporter
Copy link
Author

Thanks for the catch.  I fixed this by making the change you suggested in 
find_suboverlap_start(), and added your test as tests/issue133.c.  I noticed 
that the SEGV only seems to happen with a buffer size of 1 (2 also works, but 
the size we typically use, 1024, seems to prevent the SEGV from occurring).

Original comment by cjlee...@gmail.com on 9 Jun 2011 at 5:51

  • Changed state: FixedNeedsReview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant