[SERVER-36922] MutableDocument::hasField() can return false positives Created: 29/Aug/18  Updated: 29/Oct/23  Resolved: 11/Sep/18

Status: Closed
Project: Core Server
Component/s: Aggregation Framework, Internal Code
Affects Version/s: None
Fix Version/s: 4.1.3

Type: Bug Priority: Major - P3
Reporter: Kyle Suarez Assignee: Charlie Swanson
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query 2018-09-24
Participants:

 Description   

In SERVER-36100, charlie.swanson and I noticed that MutableDocument::hasField() tests for existence by asking its underlying storage if it has the field in its hash table. However, this will be incorrect if the field used to exist but has cleared (for example, by a $project earlier in the pipeline).

We both used a static analysis tool and believed there to be no callers of this function, but when I attempted to remove it I found there exists a single caller:

cluster_aggregate.cpp

185
    if (opCtx->getTxnNumber()) {
186
        invariant(!cmdForShards.hasField(OperationSessionInfo::kTxnNumberFieldName));
187
        cmdForShards[OperationSessionInfo::kTxnNumberFieldName] =
188
            Value(static_cast<long long>(*opCtx->getTxnNumber()));
189
    }

As part of this ticket we should either fix the function or delete it and replace the caller's usage with an equivalent check.



 Comments   
Comment by Githook User [ 11/Sep/18 ]

Author:

{'name': 'Charlie Swanson', 'email': 'charlie.swanson@mongodb.com', 'username': 'cswanson310'}

Message: SERVER-36922 Remove MutableDocument::hasField

This is unused and can sometimes be misleading if the field is present
but has the "missing" value, so will not be serialized to BSON.
Branch: master
https://github.com/mongodb/mongo/commit/4acc56425aa07c21727f107d043bd92f6cfeacbc

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