-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
When looking at how phongo handles int64 issues, I ran into the following code in WriteResult.c:
} else if (BSON_ITER_HOLDS_INT64(&outer)) { int64_t val = bson_iter_int64(&outer); #if SIZEOF_LONG == 4 if (val > INT_MAX) { add_index_long(writeresult->upsertedIds, index, (double)val); } else #endif add_index_long(return_value, index, val); }
The case for where SIZEOF_LONG is 4, seems broken if val > INT_MAX. Not only does it use add_index_long with a double value, but you can also not just cast int64 to double, as double only has 53bits precision (and not 64), resulting in potential dataloss.