MongoDB crashes with one ill-named field, what's so special about that?

Using the Java driver, we found today that we could bring up an instance of MongoDB with a segmentation error.

new Mongo().getDB("test").getCollection("test"). insert(new BasicDBObject("\u0000Žö", "")); 

This will lead to the following output from mongod before he dies:

 Fri Nov 16 18:53:18 Invalid access at address: 0xbac3c5fe from thread: conn5 Fri Nov 16 18:53:18 Got signal: 11 (Segmentation fault: 11). Fri Nov 16 18:53:18 Backtrace: 0x10004241b 0x10005628b 0x100056941 0x7fff828afcfa 0x1 0x100281611 0x100288c91 0x10006c501 0x10058e50c 0x1005e31d3 0x7fff8285b8bf 0x7fff8285eb75 0 mongod 0x000000010004241b _ZN5mongo15printStackTraceERSo + 43 1 mongod 0x000000010005628b _ZN5mongo10abruptQuitEi + 987 2 mongod 0x0000000100056941 _ZN5mongo24abruptQuitWithAddrSignalEiP9__siginfoPv + 673 3 libsystem_c.dylib 0x00007fff828afcfa _sigtramp + 26 4 ??? 0x0000000000000001 0x0 + 1 5 mongod 0x0000000100281611 _ZN5mongo14receivedInsertERNS_7MessageERNS_5CurOpE + 1841 6 mongod 0x0000000100288c91 _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 4705 7 mongod 0x000000010006c501 _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 257 8 mongod 0x000000010058e50c _ZN5mongo3pms9threadRunEPNS_13MessagingPortE + 1084 9 mongod 0x00000001005e31d3 thread_proxy + 163 10 libsystem_c.dylib 0x00007fff8285b8bf _pthread_start + 335 11 libsystem_c.dylib 0x00007fff8285eb75 thread_start + 13 

I tried to understand what really makes this magical field name special. Removing any characters makes mongodb survive just fine, and stack tracing doesn't make me wiser.

I wrote a short blog post on this issue and wrote JIRA on mongodb.org, but my curiosity is killing me. Can someone figure out what makes \u0000Žö special?

Edit to clarify : \u0000 and \u0000Ž , and that means \u0000Žsomerandomtext

+4
source share
2 answers

The reason this doesn't work is because the statement letter unicode is spoiled. It is possible that the java driver incorrectly checks the possibility that there may be unicode in the unicode literal operator;) When creating a mongo shell with such a key (copied to a terminal based on UTF8), an error is issued: BSONElement: bad type -59

+1
source

Java String can only be expressed in ASCII encoding, to get a Unicode literal, you need to get each Unicode code and build a string:

 String unicode = "\u1123\u5678hello"; 

will result in:

 ᄣ噸hello 
0
source

Source: https://habr.com/ru/post/1446522/


All Articles