From 311b286d41c4e165befd15f63126c1ef4bfd06b1 Mon Sep 17 00:00:00 2001 From: John Sully Date: Sat, 15 Aug 2020 23:30:22 +0000 Subject: [PATCH] BUG: Cannot have an EMBSTR bigger than 255 Former-commit-id: e2d6e2d9d585cb7a73f469a8580f9cb0ec71a429 --- src/object.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/object.cpp b/src/object.cpp index 382b40c02..fbbbae339 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -94,6 +94,7 @@ robj *createRawStringObject(const char *ptr, size_t len) { * an object where the sds string is actually an unmodifiable string * allocated in the same chunk as the object itself. */ robj *createEmbeddedStringObject(const char *ptr, size_t len) { + serverAssert(len <= UINT8_MAX); size_t allocsize = sizeof(struct sdshdr8)+len+1; if (allocsize < sizeof(void*)) allocsize = sizeof(void*); @@ -136,10 +137,10 @@ robj *createEmbeddedStringObject(const char *ptr, size_t len) { #ifdef ENABLE_MVCC #define OBJ_ENCODING_EMBSTR_SIZE_LIMIT 48 #else -#define OBJ_ENCODING_EMBSTR_SIZE_LIMIT 256 +#define OBJ_ENCODING_EMBSTR_SIZE_LIMIT 56 #endif -//static_assert((sizeof(redisObject)+OBJ_ENCODING_EMBSTR_SIZE_LIMIT-8) == 64, "Max EMBSTR obj should be 64 bytes total"); +static_assert((sizeof(redisObject)+OBJ_ENCODING_EMBSTR_SIZE_LIMIT-8) == 64, "Max EMBSTR obj should be 64 bytes total"); robj *createStringObject(const char *ptr, size_t len) { if (len <= OBJ_ENCODING_EMBSTR_SIZE_LIMIT) return createEmbeddedStringObject(ptr,len);