[CDRIVER-2290] OPMsg size for a Document Sequence is encoded as native endianness Created: 18/Sep/17  Updated: 28/Oct/23  Resolved: 20/Oct/17

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.9.0

Type: Bug Priority: Major - P3
Reporter: Mark Benvenuto Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-31052 "Invalid advance past end of buffer" ... Closed

 Description   

Currently, when the C driver writes the length of a document sequence payload in an OpMsg, it writes the length as native-endian instead of little-endian.

Here is the problematic line:
https://github.com/mongodb/mongo-c-driver/blob/e86e19589294b348ef8e7c547d65babb42fb089b/src/mongoc/mongoc-rpc.c#L116

Support for document sequences was added in the change below, and did the endian encoding correctly:
https://github.com/mongodb/mongo-c-driver/commit/c2073231209f20f5eef7263e969ae69ed47a031e
A regression in behavior was added in this change
https://github.com/mongodb/mongo-c-driver/commit/0f12b9d2782feef0418894bcd0134c89e21a5b5e



 Comments   
Comment by A. Jesse Jiryu Davis [ 20/Oct/17 ]

It is fixed, but BUILD-3865 had me confused.

Comment by A. Jesse Jiryu Davis [ 16/Oct/17 ]

I thought I fixed this, I was tricked by a display quirk of Evergreen. I haven't fixed it completely.

Comment by Githook User [ 14/Oct/17 ]

Author:

{'email': 'jesse@mongodb.com', 'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis'}

Message: CDRIVER-2290 OP_MSG payload type 1, big-endian fix

Don't overwrite payload.sequence.size with a little-endian int32. That
size is used later in calculations which are wrong on big-endian boxes.
Instead, write the little-endian number to a separate field.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/42d8a658f4e9178ce76a9af60fbfcc7b0c1aa041

Comment by Hannes Magnusson [ 18/Sep/17 ]

wow. Hot diddily doo! Than you so much for thorough debugging mark.benvenuto !

That payload length is indeed being written in native endian rather the little endian

Comment by A. Jesse Jiryu Davis [ 18/Sep/17 ]

Beautiful, thanks Mark.

Generated at Wed Feb 07 21:14:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.