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

BSON should throw when encountering 64-bit integer on 32-bit platform

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.2.0
    • Affects Version/s: 0.6.3
    • Component/s: None
    • None

      This only pertains to Phongo on PHP 5.x, since PHP7 will support 64-bit integers on all platforms, and HHVM requires a 64-bit platform. Currently, the driver logs a warning and stores the 64-bit integer as a string:

      #if SIZEOF_LONG == 4
      # define ADD_INDEX_INT64(zval, index, value) \
      	if (value > LONG_MAX || value < LONG_MIN) { \
      		char *tmp; \
      		int tmp_len; \
      		mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Integer overflow detected on your platform: %lld", value); \
      		tmp_len = spprintf(&tmp, 0, "%lld", value); \
      		add_index_stringl(zval, index, tmp, tmp_len, 0); \
      	} else { \
      		add_index_long(zval, index, val); \
      	}
      # define ADD_ASSOC_INT64(zval, key, value) \
      	if (value > LONG_MAX || value < LONG_MIN) { \
      		char *tmp; \
      		int tmp_len; \
      		mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Integer overflow detected on your platform: %lld", value); \
      		tmp_len = spprintf(&tmp, 0, "%lld", value); \
      		add_assoc_stringl(zval, key, tmp, tmp_len, 0); \
      	} else { \
      		add_assoc_long(zval, key, value); \
      	}
      #else
      # define ADD_INDEX_INT64(zval, index, value) add_index_long(zval, index, value)
      # define ADD_ASSOC_INT64(zval, key, value) add_assoc_long(zval, key, value);
      #endif
      

      If users do not pay attention to logging, they could inadvertently convert a 64-bit integer to a string when round-tripping a document through the driver on a 32-bit platform. Rather than keep a MongoInt64-like class around, we would rather just throw an exception when working with such values.

      This may cause problems for any command result that returns a cursor ID, since those are 64-bit and it's unlikely that the driver would know the context of the field path to deserialize it into a CursorId object.

            Assignee:
            derick Derick Rethans
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: