[SERVER-38010] Count command with no predicate and limit of min long returns incorrect result Created: 07/Nov/18  Updated: 06/Dec/22  Resolved: 09/Nov/18

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 4.0.4
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: David Storch Assignee: Backlog - Query Team (Inactive)
Resolution: Won't Fix Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-37446 Make remaining collection access stag... Closed
Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

In general, the count command treats a limit of -n as identical to a limit of n:

> db.runCommand({count: "c"})
{ "n" : 11, "ok" : 1 }
> db.runCommand({count: "c", limit: -10})
{ "n" : 10, "ok" : 1 }

This is implemented by taking the absolute value of a long long. Taking the absolute value is incorrect for the smallest negative long long, since its absolute value is too large to be represented with 64 signed bits. Consequently, the count command returns an incorrect result when the limit is -2^63:

> db.runCommand({count: "c", limit: NumberLong(-9223372036854775808)})
{ "n" : NumberLong("-9223372036854775808"), "ok" : 1 }

This bug affects 4.0, and probably older branches (but I only confirmed on 4.0). It was fixed in 4.1 development by f0b39d91840 under SERVER-37446.



 Comments   
Comment by Ian Whalen (Inactive) [ 09/Nov/18 ]

closing as Won't Fix since this is already fixed in master.

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