[CDRIVER-8] bson_append_binary produces bogus data Created: 24/Jan/10  Updated: 19/Oct/16  Resolved: 25/Jan/10

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

Type: Bug Priority: Major - P3
Reporter: Rui Lopes Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The following lines:

const int size = 4+1+len;
if ( ! bson_append_estart( b , bson_bindata , name , size ) ) return 0;
bson_append32(b, &size);

Should be replaced with:

if ( ! bson_append_estart( b , bson_bindata , name , 4+1+len ) ) return 0;
bson_append32(b, &len);

Because the first 32-bit of a binary must only account for the size of the binary data itself.

BTW, it would be nice to have a way to append an binary array (that is, bindata subtype 2, see http://www.mongodb.org/display/DOCS/BSON#BSON-noteondatabinary) without preencoding the "str" argument of bson_append_binary.



 Comments   
Comment by Rui Lopes [ 26/Jan/10 ]

Because of this note on the spec page:

Note that 0x02 is the commonly used "binary" type for carrying general binary data

I though it was the way to encode an opaque binary array. Is there a preferred way? Maybe with subtype 0x80?

Comment by Mathias Stearn [ 25/Jan/10 ]

Why do you need to use subtype 2? bson_iterator_bin_len() should be the same number that would be prefixed to the real data. Just store the array directly.

If you really need a helper for subtype 2 please open a new case.

Comment by auto [ 25/Jan/10 ]

Author:

{'login': 'RedBeard0531', 'name': 'Mathias Stearn', 'email': 'redbeard0531@gmail.com'}

Message: Fix bson_append_binary CDRIVER-8
http://github.com/mongodb/mongo-c-driver/commit/cbb524ba09cd1f2d3690192960e873e6e16f8c77

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