Skip to content

PHPC-593, PHPC-594, PHPC-595: Range checks for WriteConcern, Binary, and Timestamp #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 29, 2016

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Feb 26, 2016

@@ -0,0 +1,40 @@
--TEST--
BSON BSON\Timestamp constructor requires positive 64-bit integers <= UINT32_MAX
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does the title say positive 64-bit integers <= UNIT32_MAX? Surely, you could just say:

requires positive unsigned 32-bit integers

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I wanted to differentiate here because we do allow negative 32-bit integers (on 32-bit platforms), since we cast them to unsigned. The BSON timestamp type's two components are unsigned 32-bit integers. If we didn't cast 32-bit integers, we'd limit input to 2147483647 instead of 4294967295. I realize this is tricky and requires some documentation on PHP.net, but it seemed most flexible.

Anywho, only 64-bit integers are required to be positive, since we leave them as signed. How about:

requires 64-bit integers to be positive unsigned 32-bit integers

@derickr
Copy link
Contributor

derickr commented Feb 29, 2016

Besides the comment about the test case, this LGTM. The HHVM equivalent PR is mongodb/mongo-hhvm-driver#69

@jmikola jmikola force-pushed the phpc-593-594-595 branch 2 times, most recently from 87055a8 to d1b883c Compare February 29, 2016 16:57
This also defines a compatility constant for printing phongo_long, which may vary by PHP version and architecture.
This adds range checking to Timestamp's constructor and changes Timestamp::__toString() to print the components as unsigned 32-bit integers. Internal structs and functions were changed to use uint32_t for readability.

32-bit platforms will be limited to the range of signed 32-bit integers, since PHP has no unsigned integer type. This will be documented in PHPC-599.
This adds range checking to Binary's constructor. Internal structs and functions were changed to use uint8_t for readability.
@jmikola jmikola merged commit 9f93fbd into mongodb:master Feb 29, 2016
jmikola added a commit that referenced this pull request Feb 29, 2016
@jmikola jmikola deleted the phpc-593-594-595 branch February 29, 2016 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants