Skip to content

Conversation

@aospan
Copy link

@aospan aospan commented Sep 14, 2018

Crash observed when document length is 257 byte, for example.
It represents as '0x01 01 00 00'.
In this case '_bytes_read == _len' equal to 1 and callback is called
with partial buffer (only 1 byte actually). This cause later crash in
'to_dotted_notation_document'

Signed-off-by: Abylay Ospan aospan@netup.ru

Crash observed when document length is 257 byte, for example.
It represents as '0x01 01 00 00'.
In this case '_bytes_read == _len' equal to 1 and callback is called
with partial buffer (only 1 byte actually). This cause later crash in
'to_dotted_notation_document'

Signed-off-by: Abylay Ospan <aospan@netup.ru>

// This creates the document from the given bytes, and calls the user-provided callback.
if (_bytes_read == _len) {
if (_bytes_read == _len && _len > 4) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about earlier(e..g line 54) just returning early if _bytes_read < 4, so we're never dealing with an invalid _len in the later code?

@rkargon
Copy link

rkargon commented Sep 14, 2018

Wow, good catch!

@aospan
Copy link
Author

aospan commented Sep 14, 2018

@rkargon tnx :)

BTW, better to implement:
streamsize xsputn (const char* s, streamsize n);

then we shouldn't care about buffer assembly and avoid byte-by-byte copy (which can slow down whole process)

With mongo-cxx-3.2+ we have exception:

terminate called after throwing an instance of
'bsoncxx::v_noabi::exception'
  what():  can't convert builder to a valid view: unmatched key

while using embedded documents. For example:
    {
        "name" : "Jenny",
        "contact_info" :
            {
                "type" : "home"
            }
    }

we have called twice:
 1. for "contact_info" key
 2. for "contact_info.type" key

in mongo-cxx-3.2+ we can't call key_view/key_owned twice. Otherwise we
receive exception as described above.

Signed-off-by: Abylay Ospan <aospan@netup.ru>
Incorrect fix revert.
This reverts commit 4f0c9e9.
With modern mongo-cxx (tested on 3.3.1) we have exception while using
embedded documents:

terminate called after throwing an instance of
'bsoncxx::v_noabi::exception'
what(): can't convert builder to a valid view: unmatched key

For example:
{
    "name" : "Jenny",
    "contact_info" :
    {
        "type" : "home"
    }
}

we have called twice:
    1. for "contact_info" key
    2. for "contact_info.type" key

we can't call key_view/key_owned twice.
Otherwise we receive exception as described above.

Signed-off-by: Abylay Ospan <aospan@netup.ru>
With modern mongo-cxx (tested on 3.3.1) we have exception while using
embedded documents:

    terminate called after throwing an instance of
    'bsoncxx::v_noabi::exception'
    what(): can't convert builder to a valid view: unmatched key

For example:
{
    "name" : "Jenny",
    "contact_info" :
    {
        "type" : "home"
    }
}

we have called twice:
 1. for "contact_info" key
 2. for "contact_info.type" key

we can't call key_view/key_owned twice.
Otherwise we receive exception as described above.

Signed-off-by: Abylay Ospan <aospan@netup.ru>
Save 'key' if we do not in dot notation mode

Signed-off-by: Abylay Ospan <aospan@netup.ru>
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.

2 participants