Segmentation fault using $orderby (critical error) #182

Closed
restdbio opened this Issue Mar 7, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@restdbio

restdbio commented Mar 7, 2017

When using $orderby with sort order 1 on a collection where the first record does not contain the field we order by and the other records contains this field with both negative and positive integer values - EJDB crashes with a segmentation fault.

The following code demonstrates the problem (see comments in code):

/*
    Demonstration of error using $orderby resulting in segmentation fault
    Tested on EJDB version 1.2.10-34 and 1.2.10-35 on Mac and Linux
*/

var ejdb = require("ejdb");
var db = ejdb.open("testdb");

// remove collection (so we can run multiple times)
db.removeCollection("testcoll");

// add one odd record (has to be the first to provoke the segmentation fault)
db.save("testcoll", { "test2": "dd" });
// add one record with positive value
db.save("testcoll", { "test": 3 });
// add one record with negative value
db.save("testcoll", { "test": -1 });

setTimeout(function() {
    // this query now crashes the db (using -1 sort order does not)
    db.find("testcoll", {}, { "$orderby": { "test": 1 } }, function(err, cursor, count) {
        if (err) {
            console.error(err);
            return;
        }
        console.log("Found " + count + " objects");
        while (cursor.next()) {
            console.log(cursor.object());
        }
        //It's not mandatory to close cursor explicitly
        cursor.close();
        db.close(); //Close the database
    });
}, 1000);

/*

On Mac, sometimes I saw this:

node(6548,0x7fff780b6000) malloc: *** error for object 0x101834f28: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

*/
@adamansky

This comment has been minimized.

Show comment
Hide comment
@adamansky

adamansky Mar 9, 2017

Member

okey, got it

Member

adamansky commented Mar 9, 2017

okey, got it

tyutyunkov added a commit that referenced this issue Mar 10, 2017

tyutyunkov added a commit that referenced this issue Mar 10, 2017

@adamansky

This comment has been minimized.

Show comment
Hide comment
@adamansky

adamansky Mar 10, 2017

Member

Fixed

Member

adamansky commented Mar 10, 2017

Fixed

@adamansky adamansky closed this Mar 10, 2017

@restdbio

This comment has been minimized.

Show comment
Hide comment
@restdbio

restdbio Mar 10, 2017

Awesome work! Thanks.

Any idea when a new version with this fix will be released?

Awesome work! Thanks.

Any idea when a new version with this fix will be released?

@adamansky

This comment has been minimized.

Show comment
Hide comment
@adamansky

adamansky Mar 13, 2017

Member

We will release bug fix version up to end of this week.

Member

adamansky commented Mar 13, 2017

We will release bug fix version up to end of this week.

@adamansky adamansky reopened this Mar 13, 2017

@adamansky

This comment has been minimized.

Show comment
Hide comment

@adamansky adamansky closed this Mar 16, 2017

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