Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
076f88d6
Commit
076f88d6
authored
Dec 09, 2010
by
Pieter Noordhuis
Browse files
Enforce maximum string value length of 512MB
parent
3c1bf495
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/t_string.c
View file @
076f88d6
...
@@ -91,7 +91,7 @@ static int getBitOffsetFromArgument(redisClient *c, robj *o, size_t *offset) {
...
@@ -91,7 +91,7 @@ static int getBitOffsetFromArgument(redisClient *c, robj *o, size_t *offset) {
/* Limit offset to SIZE_T_MAX or 1GB in bytes */
/* Limit offset to SIZE_T_MAX or 1GB in bytes */
if
((
loffset
<
0
)
||
if
((
loffset
<
0
)
||
((
unsigned
long
long
)
loffset
>=
(
unsigned
)
SIZE_T_MAX
)
||
((
unsigned
long
long
)
loffset
>=
(
unsigned
)
SIZE_T_MAX
)
||
((
unsigned
long
long
)
loffset
>>
3
)
>=
(
1024
*
1024
*
1024
))
((
unsigned
long
long
)
loffset
>>
3
)
>=
(
512
*
1024
*
1024
))
{
{
addReplyError
(
c
,
err
);
addReplyError
(
c
,
err
);
return
REDIS_ERR
;
return
REDIS_ERR
;
...
@@ -263,7 +263,7 @@ void decrbyCommand(redisClient *c) {
...
@@ -263,7 +263,7 @@ void decrbyCommand(redisClient *c) {
void
appendCommand
(
redisClient
*
c
)
{
void
appendCommand
(
redisClient
*
c
)
{
int
retval
;
int
retval
;
size_t
totlen
;
size_t
totlen
;
robj
*
o
;
robj
*
o
,
*
append
;
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
...
@@ -277,23 +277,27 @@ void appendCommand(redisClient *c) {
...
@@ -277,23 +277,27 @@ void appendCommand(redisClient *c) {
addReply
(
c
,
shared
.
wrongtypeerr
);
addReply
(
c
,
shared
.
wrongtypeerr
);
return
;
return
;
}
}
/* If the object is specially encoded or shared we have to make
* a copy */
append
=
getDecodedObject
(
c
->
argv
[
2
]);
if
(
o
->
encoding
==
REDIS_ENCODING_RAW
&&
(
sdslen
(
o
->
ptr
)
+
sdslen
(
append
->
ptr
))
>
512
*
1024
*
1024
)
{
addReplyError
(
c
,
"string exceeds maximum allowed size (512MB)"
);
decrRefCount
(
append
);
return
;
}
/* If the object is shared or encoded, we have to make a copy */
if
(
o
->
refcount
!=
1
||
o
->
encoding
!=
REDIS_ENCODING_RAW
)
{
if
(
o
->
refcount
!=
1
||
o
->
encoding
!=
REDIS_ENCODING_RAW
)
{
robj
*
decoded
=
getDecodedObject
(
o
);
robj
*
decoded
=
getDecodedObject
(
o
);
o
=
createStringObject
(
decoded
->
ptr
,
sdslen
(
decoded
->
ptr
));
o
=
createStringObject
(
decoded
->
ptr
,
sdslen
(
decoded
->
ptr
));
decrRefCount
(
decoded
);
decrRefCount
(
decoded
);
dbReplace
(
c
->
db
,
c
->
argv
[
1
],
o
);
dbReplace
(
c
->
db
,
c
->
argv
[
1
],
o
);
}
}
/* APPEND! */
if
(
c
->
argv
[
2
]
->
encoding
==
REDIS_ENCODING_RAW
)
{
/* Append the value */
o
->
ptr
=
sdscatlen
(
o
->
ptr
,
o
->
ptr
=
sdscatlen
(
o
->
ptr
,
append
->
ptr
,
sdslen
(
append
->
ptr
));
c
->
argv
[
2
]
->
ptr
,
sdslen
(
c
->
argv
[
2
]
->
ptr
));
decrRefCount
(
append
);
}
else
{
o
->
ptr
=
sdscatprintf
(
o
->
ptr
,
"%ld"
,
(
unsigned
long
)
c
->
argv
[
2
]
->
ptr
);
}
totlen
=
sdslen
(
o
->
ptr
);
totlen
=
sdslen
(
o
->
ptr
);
}
}
touchWatchedKey
(
c
->
db
,
c
->
argv
[
1
]);
touchWatchedKey
(
c
->
db
,
c
->
argv
[
1
]);
...
...
tests/unit/basic.tcl
View file @
076f88d6
...
@@ -410,7 +410,7 @@ start_server {tags {"basic"}} {
...
@@ -410,7 +410,7 @@ start_server {tags {"basic"}} {
test
"SETBIT with out of range bit offset"
{
test
"SETBIT with out of range bit offset"
{
r del mykey
r del mykey
assert_error
"*out of range*"
{
r setbit mykey
[
expr
8
*1024*1024*1024
]
1
}
assert_error
"*out of range*"
{
r setbit mykey
[
expr
4
*1024*1024*1024
]
1
}
assert_error
"*out of range*"
{
r setbit mykey -1 1
}
assert_error
"*out of range*"
{
r setbit mykey -1 1
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment