[SERVER-20665] RegExp with \u0x0000 triggers stack trace Created: 28/Sep/15  Updated: 28/Sep/15  Resolved: 28/Sep/15

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.0.6
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Peak Ji Assignee: Ramon Fernandez Marina
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-18167 handle BSON validation in OP_COMMAND/... Closed
Operating System: ALL
Steps To Reproduce:

db.test.save(

{ a: (new RegExp(String.fromCharCode(0))), _id: 'test' }

)

Participants:

 Description   

I can't copy or type ASCII control chars in the browser, but we can reproduce the issue in mongo shell with some Javascript:

> db.test.save({ a: (new RegExp(String.fromCharCode(0))), _id: 'test' })
 
2015-09-29T00:52:38.841+0800 I NETWORK  DBClientCursor::init call() failed
2015-09-29T00:52:38.841+0800 E QUERY    Error: Error: error doing query: failed
    at Error (<anonymous>)
    at DBCollection.update (src/mongo/shell/collection.js:467:23)
    at DBCollection.save (src/mongo/shell/collection.js:496:21)
    at (shell):1:9 at src/mongo/shell/collection.js:467

And here the error in log:

 I - [conn117] Assertion: 10307:Client Error: bad object in message: bson length doesn't match what we found in object with unknown _id



 Comments   
Comment by Ramon Fernandez Marina [ 28/Sep/15 ]

Thanks for your report peakji; the command you sent doesn't crash the server, only triggers a stack trace because of a failed check – mongod's availability is not compromised. I've adjusted the ticket title to reflect that.

Starting with MongoDB 3.1.5 the check happens earlier and a comprehensive error message is printed instead of the stack trace:

> db.test.save({ a: (new RegExp(String.fromCharCode(0))), _id: 'test' })
WriteResult({
        "writeError" : {
                "code" : 22,
                "errmsg" : "bson length doesn't match what we found in object with unknown _id"
        }
})

Generated at Thu Feb 08 03:54:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.