★ wanayoo — archive 1999 https://github.com/phpredis/phpredis/pull/761Nouvelle recherche | Portail wanayoo
Skip to content
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

Before unserializing a Redis value with igbinary, check if it actually contains the correct header #761

Closed

Conversation

@mcuelenaere
Copy link
Contributor

mcuelenaere commented Mar 15, 2016

The bug can be reproduced with this script:

<?php
$r = new Redis();
$r->connect('localhost', 6379);
$r->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);

for ($i=0; $i < 1000; $i++) {
  $r->incr('a', -1);
}
var_dump($r->get('a'));
$r->del('a');

and will result in this output:

PHP Warning:  igbinary_unserialize_header: unsupported version: 758198320, should be 1 or 2 in /Users/mcuelenaere/Projects/phpredis/test.php on line 10
PHP Stack trace:
PHP   1. {main}() /Users/mcuelenaere/Projects/phpredis/test.php:0
PHP   2. Redis->get() /Users/mcuelenaere/Projects/phpredis/test.php:10

Warning: igbinary_unserialize_header: unsupported version: 758198320, should be 1 or 2 in /Users/mcuelenaere/Projects/phpredis/test.php on line 10

Call Stack:
    0.0007     232768   1. {main}() /Users/mcuelenaere/Projects/phpredis/test.php:0
    0.0404     242624   2. Redis->get() /Users/mcuelenaere/Projects/phpredis/test.php:10

string(5) "-1000"
@mcuelenaere
Copy link
Contributor Author

mcuelenaere commented Mar 15, 2016

This should fix #387, #301 and #39.

@michael-grunder
Copy link
Member

michael-grunder commented Mar 15, 2016

Thanks for the merge request. Is that header an 'always and forever' type thing, or could it pose problems depending on the version of igbinary?

Cheers
mike

@mcuelenaere
Copy link
Contributor Author

mcuelenaere commented Mar 15, 2016

As I couldn't find any documentation on the igbinary protocol, I based myself on the igbinary source.
More specifically here and here.

I'm not sure if this is an 'always and forever' thing, but so far there seem to have been only 2 versions of the igbinary protocol and they start with a 0x1 and 0x2 header respectively.

An alternative way would be igbinary exposing an extra function (eg bool igbinary_is_valid(const char* buf, size_t len)) that would be called instead of doing the validation inline here.

@michael-grunder
Copy link
Member

michael-grunder commented Mar 15, 2016

An alternative way would be igbinary exposing an extra function (eg bool igbinary_is_valid(const char* buf, size_t len)) that would be called instead of doing the validation inline here.

That would seem almost too logical 😃

I don't have a problem inlining the validation like this but was just wondering if we would run into versioning problems for ancient versions of igbinary. I'll pull it down and give it a test and then get it merged for you.

Thanks again!
Mike

@mcuelenaere
Copy link
Contributor Author

mcuelenaere commented Mar 16, 2016

I changed the val_len check to not include the NULL byte, as in the first commit it wasn't being written.

@michael-grunder
Copy link
Member

michael-grunder commented Mar 31, 2016

I fetched your repo and have merged this into the develop branch locally so I'll close this request. Just going to do a few tests and then you'll see it on the next push.

Then I have to do all of it again for php7 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.