-
Notifications
You must be signed in to change notification settings - Fork 8k
Detect binary prefix in intval() with base = 0 #2182
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
Conversation
|
I don't really feel very happy about the code for sending the negative value to |
|
Made the prefix check a little less terrible, I think. |
|
Uff, looks like |
|
When you do, be sure to check whitespace in the same manner it does. I think it uses the same rules as |
|
@lt bump ... |
|
@krakjoe I've added the whitespace checks, and a check for a unary '+' symbol. |
ext/standard/type.c
Outdated
| zval *num; | ||
| zend_long base = 10; | ||
|
|
||
| zend_long strlen; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be size_t
ext/standard/type.c
Outdated
|
|
||
| if (tmpval[0] == '0' && tmpval[1] == 'b') { | ||
| /* This effectively causes the string to have two leading zeros */ | ||
| tmpval[1] = '0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately doing this is not possible, as it may cause SHM corruption.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that sucks, I was trying to avoid copying the string.
ext/standard/type.c
Outdated
| tmpval++; | ||
| } | ||
|
|
||
| if (tmpval[0] == '0' && tmpval[1] == 'b') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we accept 0X next to 0x in intval? If so, 0B should be supported here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick test shows 0X is accepted.
//TODO
Nikita informs me that the previous code could cause potential SHM corruption.
ext/standard/type.c
Outdated
| offset = 1; | ||
| } | ||
|
|
||
| if (strval[offset] == '0' && (strval[offset + 1] == 'b' || strval[offset + 1] == 'B')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're missing a base==0 check somewhere around here.
| --EXPECTF-- | ||
| --- Good Inputs --- | ||
| string(34) "0b11111111111111111111111111111111" | ||
| int(4294967295) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is presumably going to have different output on 32 bit and 64 bit. We either need to fork the test or, more easily, drop one bit :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop 32-bit support \o/
|
@krakjoe This fine for 7.1? |
|
👍 |
|
Merged via 4f7b498, thanks! |
https://bugs.php.net/bug.php?id=73374
strtolldoesn't detect0bas a prefix so we have to fake it.