[SERVER-61795] Incorrect Usage of Javascript Comparison to Compare Arrays and Objects Created: 30/Nov/21  Updated: 29/Oct/23  Resolved: 10/Feb/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 5.1.0-rc3
Fix Version/s: 5.3.0

Type: Bug Priority: Major - P3
Reporter: Mohammad Dashti (Inactive) Assignee: Justin Seyster
Resolution: Fixed Votes: 0
Labels: greenerbuild, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

You can run the test like this:

activate && buildscripts/resmoke.py run --suites=aggregation --installDir=dist-test/bin --continueOnFailure --excludeWithAnyTags=requires_http_client --spawnUsing=python --jobs=4 --shuffle --storageEngineCacheSizeGB=1 jstests/aggregation/expressions/expression_trigonometric.js

You can change the expected result of any test done with testOpApprox in this file and all tests still pass. For example, you can replace:

testOpApprox({$acos: NumberDecimal(1)}, NumberDecimal(0));

with:

testOpApprox({$acos: NumberDecimal(1)}, NumberDecimal(100));

and the test-suite passes.

Participants:

 Description   

The tests in expression_trigonometric.js use assert.lt (in here) to compare the array of results returned from the aggregation pipeline with an array created in JavaScript. Then, the implementation of assert.lt (in here) uses the < JavaScript operator to perform the less-than comparison. As JavaScript does not provide operator overloading, to perform the comparison between arrays or objects, calls toString on them and compares the results. For objects, toString always returns "[object Object]" for JavaScript-created objects and "[object BSON]" for BSON objects (usually returned from an aggregation pipeline). Then, the comparison here always returns true irrespective of the values, as long as a value exists.

This is just one instance and we should keep an eye for other tests that might suffer from the same incorrect usage of JavaScript comparison operators.

 



 Comments   
Comment by Githook User [ 07/Feb/22 ]

Author:

{'name': 'Justin Seyster', 'email': 'justin.seyster@mongodb.com', 'username': 'jseyster'}

Message: SERVER-61795 Fix comparisons in expression_trigonometric.js
Branch: master
https://github.com/mongodb/mongo/commit/52c017336905d7219ef6e3f51ee78c9dd958df4e

Generated at Thu Feb 08 05:53:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.