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

Reading bigWig files sometimes fails: Uninitialized bwRTree_t->root variable #85

Closed
pbenner opened this issue May 14, 2019 · 2 comments
Closed

Comments

@pbenner
Copy link

pbenner commented May 14, 2019

node = malloc(sizeof(bwRTree_t));

A new root node is allocated here using malloc (not calloc), which leaves node->root uninitialized.

fp->idx = readRTreeIdx(fp, fp->hdr->indexOffset);

Here the index is read.

if(!fp->idx->root) fp->idx->root = bwGetRTreeNode(fp, 0);

And here the RTree is parsed only if idx->root is not zero, assuming that it was initialized to zero by readRTreeIdx, which is not the case.

Possible fix:

--- a/libBigWig/bwValues.c
+++ b/libBigWig/bwValues.c
@@ -35,6 +35,7 @@ static bwRTree_t *readRTreeIdx(bigWigFile_t *fp, uint64_t offset) {
 
     node = malloc(sizeof(bwRTree_t));
     if(!node) return NULL;
+    node->root = 0;
 
     if(bwRead(&(node->blockSize), sizeof(uint32_t), 1, fp) != 1) goto error;
     if(bwRead(&(node->nItems), sizeof(uint64_t), 1, fp) != 1) goto error;
@dpryan79
Copy link
Collaborator

Good catch, I'll change that to calloc.

@dpryan79
Copy link
Collaborator

I'll push out a version with this fixed now.

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

No branches or pull requests

2 participants