[SERVER-5796] HexData undocumented, crashy Created: 09/May/12  Updated: 11/Jul/16  Resolved: 01/Jun/12

Status: Closed
Project: Core Server
Component/s: Shell, Usability
Affects Version/s: 2.1.1
Fix Version/s: 2.1.2

Type: Bug Priority: Minor - P4
Reporter: A. Jesse Jiryu Davis Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-5842 Exceptions thrown in scripting/engine... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

'help misc' doesn't document how to format a hex string for the HexData constructor on the shell. Two attempts I made resulted in an assert and a crash, respectively:

> var b = new HexData(0, '0x64')
Wed May  9 11:52:20   Assertion failure false src/mongo/scripting/../db/../bson/../util/hex.h 29
0x100098001 0x10009a0ed 0x1001d6a50 0x1001d82a5 0x100172352 0x100172f55 0x1001656c3 0x100171be9 0x1001275db 0x1001ea5ab 0x100008ec1 0x10000b15a 0x100000c14 0x1 
 0   mongo                               0x0000000100098001 _ZN5mongo12sayDbContextEPKc + 161
 1   mongo                               0x000000010009a0ed _ZN5mongo8assertedEPKcS1_j + 269
 2   mongo                               0x00000001001d6a50 _ZN5mongo12hexToBinDataEP9JSContextPliSs + 752
 3   mongo                               0x00000001001d82a5 _ZN5mongo8_HexDataEP9JSContextP8JSObjectjPlS4_ + 197
 4   mongo                               0x0000000100172352 js_Invoke + 1218
 5   mongo                               0x0000000100172f55 js_InvokeConstructor + 261
 6   mongo                               0x00000001001656c3 js_Interpret + 14899
 7   mongo                               0x0000000100171be9 js_Execute + 409
 8   mongo                               0x00000001001275db JS_EvaluateScript + 219
 9   mongo                               0x00000001001ea5ab _ZN5mongo7SMScope4execERKNS_10StringDataERKSsbbbi + 475
 10  mongo                               0x0000000100008ec1 _Z5_mainiPPc + 6113
 11  mongo                               0x000000010000b15a main + 42
 12  mongo                               0x0000000100000c14 start + 52
 13  ???                                 0x0000000000000001 0x0 + 1
error:assertion src/mongo/scripting/../db/../bson/../util/hex.h:29
 
 
> var b = new HexData(0, '64')
Wed May  9 11:52:27 mongo got signal 11 (Segmentation fault: 11), stack trace: 
 
Wed May  9 11:52:27 0x100001afc 0x7fff9a334cfa 0x10050ffa0 0x1001e143b 0x100008b7e 0x10000b15a 0x100000c14 0x1 
 0   mongo                               0x0000000100001afc _Z12quitAbruptlyi + 316
 1   libsystem_c.dylib                   0x00007fff9a334cfa _sigtramp + 26
 2   ???                                 0x000000010050ffa0 0x0 + 4300275616
 3   mongo                               0x00000001001e143b _ZN5mongo7SMScope4typeEPKc + 75
 4   mongo                               0x0000000100008b7e _Z5_mainiPPc + 5278
 5   mongo                               0x000000010000b15a main + 42
 6   mongo                               0x0000000100000c14 start + 52
 7   ???                                 0x0000000000000001 0x0 + 1



 Comments   
Comment by Tad Marshall [ 01/Jun/12 ]

Added minimal added help to the shell's "help misc", added more user friendly validation and error message display when hex data does not match requirements, prevent segfaults following failed JavaScript commands.

Comment by auto [ 01/Jun/12 ]

Author:

{u'login': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-5796 add one line to shell's "help misc"

Add one line of explanation of what "hexstr" is supposed
to be to help users of HexData(), UUID and MD5().
Branch: master
https://github.com/mongodb/mongo/commit/32c4381ffa76c651c825bae3249f566493d12c8f

Comment by Tad Marshall [ 22/May/12 ]

The "crashy" part of this will be fixed by fixing SERVER-5842.

Comment by A. Jesse Jiryu Davis [ 10/May/12 ]

Right, both.

Turns out this is a weird bug. It's specifically the sequence of:

var b = new HexData(0, '0x64');
var b = new HexData(0, '64');

.... that crashes the shell. Both 'var' and 'new' keywords are needed for the crash. '64' is not special, other numbers will crash it.

However, I think the string format passed to HexData should be included in the 'help misc' output, specifically that '0x' should not be part of the string. Also, instead of a C++ traceback, it might just say, "bad format."

Comment by Tad Marshall [ 10/May/12 ]

The assertion happens because the _HexData() routine in scripting/engine_spidermonkey.cpp (lines starting at 958 in today's code) does no pre-testing of the string and passes it directly to a helper function that asserts (verify in today's code) on any character other than 0-9 and a-f(A-F). The 'x' triggers the failure. If you pass a number of arguments other than two, you get a friendly error message. Pass a non-hex character and you get the stack trace.

Testing on Windows, the second example works, though the variable 'b' is displayed as BinData(0,"ZA==") and not as HexData as I had expected.

I'd vote for a friendly error message on invalid input (e.g. "Error: 'x' is not a hexadecimal digit") and no assertion or stack trace. I'd vote for no segfaults under any circumstances. The documentation should state that the second parameter should be a string containing a sequence of hexadecimal digits that is even in length.

Comment by Ian Whalen (Inactive) [ 09/May/12 ]

were you suggesting we need more docs and to handle the failure state
better? or just more docs?

On Wed, May 9, 2012 at 12:09 PM, A. Jesse Jiryu Davis (JIRA) <


Ian Whalen
10gen, The MongoDB Company
We're hiring: http://www.10gen.com/careers

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