Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-61846

Prevent redact from throwing BSONObjectTooLarge

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.3.0, 5.2.0, 5.0.6, 4.4.11
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • v5.2, v5.0, v4.4
    • Hide

      The described behavior is demonstrated by adding the following to redaction_test.cpp

      TEST(RedactBSONTest, RedactCausesBSONTooLarge) {
          logv2::setShouldRedactLogs(true);
          BSONObjBuilder bob;
          for (int i = 0; i < 1024 * 1024; i++) {
              auto fieldName = "abcdefg";
              // The value of each field is smaller than the size of the kRedactionDefaultMask.
              bob.append(fieldName, 1);
          }
          const auto obj = bob.obj();
          // Demonstrates it is possible to grow a BSON too large by redacting fields.
          ASSERT_THROWS_CODE(redact(obj), DBException, ErrorCodes::BSONObjectTooLarge);
      }
      
      Show
      The described behavior is demonstrated by adding the following to  redaction_test.cpp TEST(RedactBSONTest, RedactCausesBSONTooLarge) { logv2::setShouldRedactLogs( true ); BSONObjBuilder bob; for ( int i = 0; i < 1024 * 1024; i++) { auto fieldName = "abcdefg" ; // The value of each field is smaller than the size of the kRedactionDefaultMask. bob.append(fieldName, 1); } const auto obj = bob.obj(); // Demonstrates it is possible to grow a BSON too large by redacting fields. ASSERT_THROWS_CODE(redact(obj), DBException, ErrorCodes::BSONObjectTooLarge); }
    • Execution Team 2021-12-13

      redact replaces BSONObj field values with the kRedactionDefaultMask string "###".

      A redacted BSONObj can throw BSONObjectTooLarge if a valid BSONObj has many fields with values smaller than the kRedactionDefaultMask string size.

      ex) 
      BSON("foodIsGood" << 1) is smaller than
      redact(BSON("foodIsGood" << 1)) which yields BSON("foodIsGood": "###")

      This can cause real problems on startup if, say, we try to apply a large oplog entry close to the limit full of arrays of ints that get expanded to "###" and cause the startup to fail with a DBException

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            haley.connelly@mongodb.com Haley Connelly
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: