[SERVER-6165] use of an integer valued double with a $mod expression can produce an incorrect result Created: 21/Jun/12  Updated: 11/Jul/16  Resolved: 03/Jul/12

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 2.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Matt Dannenberg
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-6206 need a policy for incompatible types ... Closed
Operating System: ALL
Participants:

 Description   

Observed behavior: If one of the arguments to $mod is a double, the left argument is cast to an int (not a long long) before the modulus is calculated. This can result in a loss of information in the left operand before the modulus is calculated.
Expected behavior: Casting to an int does not occur in this case because it can alter the $mod result due to data loss.

c = db.c;
c.drop();
 
c.save( {} );
 
// The correct mod is calculated.
assert.eq( 1, c.aggregate( { $project:{ z:{ $mod:[ NumberLong('4294967296'), NumberLong( 3 ) ] } } } ).re\
sult[ 0 ].z );
 
// An incorrect mod is calculated due to a lossy integer conversion in ExpressionMod::evaluate.
assert.eq( 1, c.aggregate( { $project:{ z:{ $mod:[ NumberLong('4294967296'), 3.0 ] } } } ).result[ 0 ].z \
);



 Comments   
Comment by auto [ 04/Jul/12 ]

Author:

{u'date': u'2012-07-03T20:10:51-07:00', u'name': u'Mathias Stearn', u'email': u'redbeard0531@gmail.com'}

Message: Don't use trunc() as it doesn't exist on windows SERVER-6165
Branch: master
https://github.com/mongodb/mongo/commit/b84d28b8bd80603ce3c47f2a230914276c1bdb32

Comment by auto [ 03/Jul/12 ]

Author:

{u'date': u'2012-06-25T08:54:08-07:00', u'email': u'dannenberg.matt@gmail.com', u'name': u'Matt Dannenberg'}

Message: SERVER-6165 fix $mod to work with any numerictype
Branch: master
https://github.com/mongodb/mongo/commit/d13d5f4016ae3857e719890e09a8aef8dd3c9a5c

Comment by Eliot Horowitz (Inactive) [ 26/Jun/12 ]

We should just uassert on doubles anywhere in $mod

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