Skip to content

Commit a6e3d84

Browse files
Gabriel Russellevergreen
authored andcommitted
Revert "SERVER-41994 correctly create and show type 2 binary elements"
This reverts commit 3f6ba75.
1 parent 380711e commit a6e3d84

File tree

5 files changed

+7
-38
lines changed

5 files changed

+7
-38
lines changed

src/mongo/bson/bsonelement.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,7 @@ void BSONElement::jsonStringStream(JsonStringFormat format,
213213
BinDataType type = static_cast<BinDataType>(reader.readAndAdvance<uint8_t>());
214214

215215
s << "{ \"$binary\" : \"";
216-
if (type == ByteArrayDeprecated && len >= 4) {
217-
base64::encode(s, reader.view() + 4, len - 4);
218-
} else {
219-
base64::encode(s, reader.view(), len);
220-
}
216+
base64::encode(s, reader.view(), len);
221217

222218
auto origFill = s.fill();
223219
auto origFmtF = s.flags();

src/mongo/bson/bsonelement.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -494,18 +494,9 @@ class BSONElement {
494494
if (binDataType() != ByteArrayDeprecated) {
495495
return binData(len);
496496
} else {
497-
// Because, for some time, the shell has incorrectly created type 2 binary objects
498-
// without the extra length, we try to identify if this object does or doesn't start
499-
// with a length and skip past it when its present. See SERVER-41994
500-
if (valuestrsize() >= 4 &&
501-
ConstDataView(value() + 5).read<LittleEndian<int>>() == valuestrsize() - 4) {
502-
// Skip extra size
503-
len = valuestrsize() - 4;
504-
return value() + 5 + 4;
505-
} else {
506-
len = valuestrsize();
507-
return value() + 5;
508-
}
497+
// Skip extra size
498+
len = valuestrsize() - 4;
499+
return value() + 5 + 4;
509500
}
510501
}
511502

src/mongo/bson/bsonelement_test.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,6 @@ TEST(BSONElement, BinDataToString) {
7272
builder.appendBinData(
7373
"unknownType", unknownType.size(), unknownBinDataType, unknownType.rawData());
7474

75-
builder.bb().appendNum((char)BinData);
76-
builder.bb().appendStr("brokenType2");
77-
builder.bb().appendNum(3);
78-
builder.bb().appendNum((char)ByteArrayDeprecated);
79-
builder.bb().appendBuf("foo", 3);
80-
81-
builder.bb().appendNum((char)BinData);
82-
builder.bb().appendStr("fixedType2");
83-
builder.bb().appendNum(4 + 3);
84-
builder.bb().appendNum((char)ByteArrayDeprecated);
85-
builder.bb().appendNum(3);
86-
builder.bb().appendBuf("foo", 3);
87-
8875
BSONObj obj = builder.obj();
8976
ASSERT_EQ(obj["bintype0"].toString(), "bintype0: BinData(0, DEEABEEF01)");
9077
ASSERT_EQ(obj["validUUID"].toString(), "validUUID: UUID(\"" + validUUID.toString() + "\")");
@@ -96,8 +83,6 @@ TEST(BSONElement, BinDataToString) {
9683
ASSERT_EQ(obj["unknownType"].toString(),
9784
"unknownType: BinData(42, "
9885
"62696E6172792064617461007769746820616E20756E6B6E6F776E2074797065)");
99-
ASSERT_EQ(obj["brokenType2"].toString(), "brokenType2: BinData(2, 666F6F)");
100-
ASSERT_EQ(obj["fixedType2"].toString(), "fixedType2: BinData(2, 666F6F)");
10186
}
10287

10388

src/mongo/bson/bsonobjbuilder.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,6 @@ class BSONObjBuilder {
513513
int len,
514514
BinDataType type,
515515
const void* data) {
516-
if (type == ByteArrayDeprecated) {
517-
return appendBinDataArrayDeprecated(fieldName, data, len);
518-
}
519516
_b.appendNum((char)BinData);
520517
_b.appendStr(fieldName);
521518
_b.appendNum(len);
@@ -534,11 +531,11 @@ class BSONObjBuilder {
534531
@param data a byte array
535532
@param len the length of data
536533
*/
537-
BSONObjBuilder& appendBinDataArrayDeprecated(StringData fieldName, const void* data, int len) {
534+
BSONObjBuilder& appendBinDataArrayDeprecated(const char* fieldName, const void* data, int len) {
538535
_b.appendNum((char)BinData);
539536
_b.appendStr(fieldName);
540537
_b.appendNum(len + 4);
541-
_b.appendNum((char)ByteArrayDeprecated);
538+
_b.appendNum((char)0x2);
542539
_b.appendNum(len);
543540
_b.appendBuf(data, len);
544541
return *this;

src/mongo/scripting/mozjs/valuereader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void ValueReader::fromBSONElement(const BSONElement& elem, const BSONObj& parent
136136
}
137137
case mongo::BinData: {
138138
int len;
139-
const char* data = elem.binDataClean(len);
139+
const char* data = elem.binData(len);
140140
std::stringstream ss;
141141
base64::encode(ss, data, len);
142142

0 commit comments

Comments
 (0)