[SERVER-11064] Stricter validation of index key patterns during index creation and startup Created: 07/Oct/13  Updated: 17/May/19  Resolved: 27/Jan/16

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.4.6
Fix Version/s: 3.3.1

Type: Bug Priority: Major - P3
Reporter: Oleg Rekutin Assignee: Max Hirschhorn
Resolution: Done Votes: 0
Labels: neweng, query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File server11064.js     Text File server11064.patch    
Issue Links:
Depends
Documented
is documented by DOCS-7038 Document new restrictions on index ke... Closed
Duplicate
is duplicated by SERVER-12538 Possible to create indexes with inval... Closed
Related
related to SERVER-26659 Only apply stricter index key pattern... Closed
related to SERVER-5826 Creating an index using a non-existin... Closed
related to SERVER-11568 query optimizer fails to use index wh... Closed
related to SERVER-21663 Invalid parameter to ensureIndex can ... Closed
related to SERVER-11374 Can create indexes on non-insertable ... Closed
Backwards Compatibility: Major Change
Operating System: ALL
Sprint: Query F (02/01/16)
Participants:
Linked BF Score: 0

 Description   

The values in the index key pattern will be restricted to

  • numbers > 0 (ascending)
  • numbers < 0 (descending)
  • strings (special index types)

Some specific values that may be of interest for which an error will be returned under the new scheme:

  • 0
  • NaN
  • undefined and null
  • true and false
  • MinKey and MaxKey

Original description

ensureIndex permits any numeric value to be passed as the sort order. Negative values indicate descending order, greater than or equal to zero indicate ascending.

We should just limit to 1 and -1.

This was partially fixed with SERVER-5826, but only applies to non-numeric values.



 Comments   
Comment by Githook User [ 27/Jan/16 ]

Author:

{u'username': u'visemet', u'name': u'Max Hirschhorn', u'email': u'max.hirschhorn@mongodb.com'}

Message: SERVER-11064 Stricter validation of index key patterns.

Each value in the index key pattern must be one of the following:

  • a number > 0 (ascending)
  • a number < 0 (descending)
  • a string (special index type)

Since the key pattern is validated on startup for all existing indexes,
mongod will fail to start up if an index not meeting the above criteria
exists.

Additionally, if an index with an invalid key pattern is replicated from
an older version, then newer versions of mongod running in a
mixed-version replica set will fassert().
Branch: master
https://github.com/mongodb/mongo/commit/ffe490c80ecea03b02a0b20d55915c4efd2805e8

Comment by Max Hirschhorn [ 25/Jan/16 ]

Updating the description of this ticket after discussing with members of the drivers team about the following two questions:

  1. Do any current or legacy drivers perform an internal operation to an create index (e.g. GridFS) that uses a value other than strings, numbers > 0, or numbers < 0?
  2. Does the programming language of any current or legacy driver encourage using values for specifying an index type/direction other than with strings, numbers > 0, or numbers < 0?
Comment by David Storch [ 21/Dec/15 ]

Not sure that we should disallow numeric values other than +1/-1, but it seems non-controversial to reject the following kinds of values:

  • NaN
  • undefined
  • JavaScript code
  • BinData
Comment by David Storch [ 12/Nov/13 ]

Attaching a js test that should pass once this issue is resolved.

Comment by Oleg Rekutin [ 07/Oct/13 ]

Sort direction "0" is not a valid direction. This is what causes this behavior. PEBKAC, sorry. You can close this as invalid. Or change this issue in having ensureIndices validate the input, such that you can't create an index with an invalid sort direction.

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