summaryrefslogtreecommitdiff
path: root/jstests/disk
diff options
context:
space:
mode:
authorRichard Hausman <richard.hausman@mongodb.com>2022-08-09 14:19:38 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-09 16:08:36 +0000
commitdd1737cd88864b9051dd018c7a449d34b59cc347 (patch)
tree5133ac59c5d4dc0284be0143e8438b1c5b31310f /jstests/disk
parentd19f16b760c4c6ae4f4729557b548a11649b670b (diff)
downloadmongo-dd1737cd88864b9051dd018c7a449d34b59cc347.tar.gz
SERVER-67881 : Check unsupported regular expression options in BSON documents in the validate command.
Diffstat (limited to 'jstests/disk')
-rw-r--r--jstests/disk/libs/wt_file_helper.js34
-rw-r--r--jstests/disk/validate_bson_inconsistency.js29
2 files changed, 63 insertions, 0 deletions
diff --git a/jstests/disk/libs/wt_file_helper.js b/jstests/disk/libs/wt_file_helper.js
index adf05b779ed..e21c4bf1375 100644
--- a/jstests/disk/libs/wt_file_helper.js
+++ b/jstests/disk/libs/wt_file_helper.js
@@ -319,4 +319,38 @@ let insertDocSymbolField = function(coll, uri, conn, numDocs) {
}
};
rewriteTable(uri, conn, makeSymbolField);
+};
+
+/**
+ * Inserts documents with invalid regex options into the MongoDB server.
+ */
+let insertInvalidRegex = function(coll, mongod, nDocuments) {
+ const regex = "a*.conn";
+ const options = 'gimsuy';
+
+ // First, insert valid expressions which will not be rejected by the JS interpreter.
+ for (let i = 0; i < nDocuments; i++) {
+ coll.insert({a: RegExp(regex, options)});
+ }
+
+ // Insert one valid expression and 4 invalid expressions.
+ let swapOptions = function(lines) {
+ const toInsert = ["imlsux", "imzsux", "xuslmi", "amlsux"];
+ const offsetToOptionStr = 64;
+ const toHexStr = function(str) {
+ return str.split('')
+ .map((a) => {
+ return a.charCodeAt(0).toString(16);
+ })
+ .join('');
+ };
+
+ let modifiedOptions;
+ for (let i = wtHeaderLines; i < lines.length; i += 2) {
+ modifiedOptions = toHexStr(toInsert[((i - wtHeaderLines) / 2) % toInsert.length]);
+ lines[i] = lines[i].substring(0, offsetToOptionStr) + modifiedOptions +
+ lines[i].substring(offsetToOptionStr + modifiedOptions.length);
+ }
+ };
+ rewriteTable(getUriForColl(coll), mongod, swapOptions);
}; \ No newline at end of file
diff --git a/jstests/disk/validate_bson_inconsistency.js b/jstests/disk/validate_bson_inconsistency.js
index d29ae740f8c..e16faf3527f 100644
--- a/jstests/disk/validate_bson_inconsistency.js
+++ b/jstests/disk/validate_bson_inconsistency.js
@@ -66,6 +66,35 @@ resetDbpath(dbpath);
MongoRunner.stopMongod(mongod, null, {skipValidation: true});
})();
+(function validateDocumentsInvalidRegexOptions() {
+ let mongod = startMongodOnExistingPath(dbpath);
+ let db = mongod.getDB(baseName);
+
+ const collName = collNamePrefix + count++;
+ db.getCollection(collName).drop();
+ assert.commandWorked(db.createCollection(collName));
+ let coll = db[collName];
+
+ jsTestLog(
+ "Checks that issues are found when we validate regex expressions with invalid options.");
+ insertInvalidRegex(coll, mongod, 5);
+ mongod = startMongodOnExistingPath(dbpath);
+ db = mongod.getDB(baseName);
+ coll = db[collName];
+
+ let res = coll.validate({checkBSONConsistency: false});
+ assert(res.valid, tojson(res));
+ assert.eq(res.nNonCompliantDocuments, 5);
+ assert.eq(res.warnings.length, 1);
+
+ res = coll.validate({checkBSONConsistency: true});
+ assert(res.valid, tojson(res));
+ assert.eq(res.nNonCompliantDocuments, 5);
+ assert.eq(res.warnings.length, 1);
+
+ MongoRunner.stopMongod(mongod, null, {skipValidation: true});
+})();
+
(function validateDocumentsInvalidMD5Length() {
jsTestLog("Validate document with invalid MD5 length");