Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-197

Issues with 64bit IDs in getUpsertedIDs

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 0.4.0
    • 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.

            Assignee:
            bjori Hannes Magnusson
            Reporter:
            derick Derick Rethans
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: