Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 63ab29e

Browse files
Merge remote-tracking branch 'mcuel/check-igbinary-header' into develop
2 parents 200afe6 + 5528297 commit 63ab29e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

library.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,30 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
21562156

21572157
case REDIS_SERIALIZER_IGBINARY:
21582158
#ifdef HAVE_REDIS_IGBINARY
2159+
/*
2160+
* Check if the given string starts with an igbinary header.
2161+
*
2162+
* A modern igbinary string consists of the following format:
2163+
*
2164+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2165+
* | header (4) | type (1) | ... (n) | NUL (1) |
2166+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2167+
*
2168+
* With header being either 0x00000001 or 0x00000002
2169+
* (encoded as big endian).
2170+
*
2171+
* Not all versions contain the trailing NULL byte though, so
2172+
* do not check for that.
2173+
*/
2174+
if (val_len < 5
2175+
|| (memcmp(val, "\x00\x00\x00\x01", 4) != 0
2176+
&& memcmp(val, "\x00\x00\x00\x02", 4) != 0))
2177+
{
2178+
/* This is most definitely not an igbinary string, so do
2179+
not try to unserialize this as one. */
2180+
return 0;
2181+
}
2182+
21592183
if(!*return_value) {
21602184
MAKE_STD_ZVAL(*return_value);
21612185
rv_free = 1;

0 commit comments

Comments
 (0)