[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL for-2.5 13/13] qjson: Limit number of tokens in addit
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL for-2.5 13/13] qjson: Limit number of tokens in addition to total size |
Date: |
Thu, 26 Nov 2015 13:47:58 +0100 |
Commit 29c75dd "json-streamer: limit the maximum recursion depth and
maximum token count" attempts to guard against excessive heap usage by
limiting total token size (it says "token count", but that's a lie).
Total token size is a rather imprecise predictor of heap usage: many
small tokens use more space than few large tokens with the same input
size, because there's a constant per-token overhead: 37 bytes on my
system.
Tighten this up: limit the token count to 2Mi. Chosen to roughly
match the 64MiB total token size limit.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
---
qobject/json-streamer.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c
index e87230d..a4db4b8 100644
--- a/qobject/json-streamer.c
+++ b/qobject/json-streamer.c
@@ -16,6 +16,7 @@
#include "qapi/qmp/json-streamer.h"
#define MAX_TOKEN_SIZE (64ULL << 20)
+#define MAX_TOKEN_COUNT (2ULL << 20)
#define MAX_NESTING (1ULL << 10)
static void json_message_free_tokens(JSONMessageParser *parser)
@@ -68,6 +69,7 @@ static void json_message_process_token(JSONLexer *lexer,
GString *input,
parser->bracket_count == 0)) {
goto out_emit;
} else if (parser->token_size > MAX_TOKEN_SIZE ||
+ g_queue_get_length(parser->tokens) > MAX_TOKEN_COUNT ||
parser->bracket_count + parser->brace_count > MAX_NESTING) {
/* Security consideration, we limit total memory allocated per object
* and the maximum recursion depth that a message can force.
--
2.4.3
- [Qemu-devel] [PULL for-2.5 00/13] QMP and QObject patches, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 08/13] qjson: Inline token_is_escape() and simplify, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 04/13] check-qjson: Add test for JSON nesting depth limit, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 13/13] qjson: Limit number of tokens in addition to total size,
Markus Armbruster <=
- [Qemu-devel] [PULL for-2.5 02/13] qjson: Apply nesting limit more sanely, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 01/13] monitor: Plug memory leak on QMP error, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 09/13] qjson: replace QString in JSONLexer with GString, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 11/13] qjson: store tokens in a GQueue, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 03/13] qjson: Don't crash when input exceeds nesting limit, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 10/13] qjson: Convert to parser to recursive descent, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 06/13] qjson: Give each of the six structural chars its own token type, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 07/13] qjson: Inline token_is_keyword() and simplify, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 05/13] qjson: Spell out some silent assumptions, Markus Armbruster, 2015/11/26
- [Qemu-devel] [PULL for-2.5 12/13] qjson: surprise, allocating 6 QObjects per token is expensive, Markus Armbruster, 2015/11/26