[SERVER-70158] Fix undefined argument order for $atan2 in SBE Created: 03/Oct/22  Updated: 29/Oct/23  Resolved: 20/Oct/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.0.4, 6.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: Ivan Fefer Assignee: Adi Agrawal
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
is related to SERVER-68222 Make arguments evaluation order consi... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v6.1, v6.0
Sprint: QE 2022-10-31
Participants:

 Description   

In SBE implementation for atan2 we extract arguments for atan2 in undefined order because _context->popExpr() is called several times as function argument:
https://github.com/mongodb/mongo/blob/424befe581c9aeb29e42f05c0b1439ba2e39af98/src/mongo/db/query/sbe_stage_builder_expression.cpp#L3481

C++ doesn't specify the order of computation for function argument, so with any compiler upgrader and/or change in compilation flags this function can break.



 Comments   
Comment by Githook User [ 16/Nov/22 ]

Author:

{'name': 'Adityavardhan Agrawal', 'email': 'aa729@cornell.edu', 'username': 'Adityav369'}

Message: SERVER-70158 Specify argument evaluation order in generateTrigExpressionBinary

(cherry picked from commit fb7df9a15a313857c87c1661cda126049fe410bf)
Branch: v6.0
https://github.com/mongodb/mongo/commit/2a8e2affe2e3f0d7bc161efcee6796de4fa5471c

Comment by Githook User [ 20/Oct/22 ]

Author:

{'name': 'Adityavardhan Agrawal', 'email': 'aa729@cornell.edu', 'username': 'Adityav369'}

Message: SERVER-70158 Specify argument evaluation order in generateTrigExpressionBinary
Branch: master
https://github.com/mongodb/mongo/commit/fb7df9a15a313857c87c1661cda126049fe410bf

Comment by Ivan Fefer [ 03/Oct/22 ]

Also basic jstests for trigonometric expressions are not executed in SBE because they use $addFields: https://github.com/mongodb/mongo/blob/424befe581c9aeb29e42f05c0b1439ba2e39af98/jstests/aggregation/expressions/expression_trigonometric.js#L22

This should be fixed in this ticket to ensure that the fix is correct.

Generated at Thu Feb 08 06:15:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.