-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Not Needed
-
The BSON library currently includes 4 BSON-to-Go numeric value conversion functions that can cause silent data loss:
- AsInt32/AsInt32OK
- AsInt64/AsInt64OK
While converting BSON numeric types to a Go int64 can cause data loss in some cases, it's generally for extremely large or extremely small values that most users never encounter (values > 9.2e+18 or < -9.2e+18). However, converting BSON numeric types to a Go int32 can cause data loss for values that users may commonly encounter (values > 2,147,483,647 or < -2,147,483,648). As a result, using AsInt32/AsInt32OK is practically much less safe than AsInt64/AsInt64OK so we should deprecate AsInt32/AsInt32OK and recommend people use AsInt64/AsInt64OK instead. If users really need an int32, they can convert the int64 to an int32 themselves and implement whatever overflow/underflow checking logic they require.
See GODRIVER-2751 for changes to prevent data loss in AsInt64/AsInt64OK.
Definition of done:
- Deprecate frequently lossy bson.RawValue methods AsInt32 and AsInt32OK.
- is related to
-
GODRIVER-2751 Make all BSON-to-Go numeric type conversions safe
- Backlog
- related to
-
GODRIVER-632 Add As* methods to bsoncore.Value, bson.RawValue, and bson.Val types
- Closed