Disallow Token lengths over 2 GB.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/d6135b56 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/d6135b56 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/d6135b56 Branch: refs/heads/master Commit: d6135b56c13257c044853aa5dd8fa16f1478018a Parents: 2fe08b3 Author: Marvin Humphrey <[email protected]> Authored: Mon May 2 16:41:36 2016 -0700 Committer: Marvin Humphrey <[email protected]> Committed: Mon May 2 16:41:36 2016 -0700 ---------------------------------------------------------------------- core/Lucy/Analysis/Token.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/d6135b56/core/Lucy/Analysis/Token.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Analysis/Token.c b/core/Lucy/Analysis/Token.c index e365d06..236e17e 100644 --- a/core/Lucy/Analysis/Token.c +++ b/core/Lucy/Analysis/Token.c @@ -32,19 +32,18 @@ Token_init(Token *self, const char* text, size_t len, uint32_t start_offset, uint32_t end_offset, float boost, int32_t pos_inc) { TokenIVARS *const ivars = Token_IVARS(self); - // Allocate and assign. + if (len > INT32_MAX) { + THROW(ERR, "Token length greater than 2 GB: %u64", (uint64_t)len); + } ivars->text = (char*)MALLOCATE(len + 1); ivars->text[len] = '\0'; memcpy(ivars->text, text, len); - // Assign. ivars->len = len; ivars->start_offset = start_offset; ivars->end_offset = end_offset; ivars->boost = boost; ivars->pos_inc = pos_inc; - - // Init. ivars->pos = -1; return self; @@ -117,6 +116,9 @@ void Token_Set_Text_IMP(Token *self, char *text, size_t len) { TokenIVARS *const ivars = Token_IVARS(self); if (len > ivars->len) { + if (len > INT32_MAX) { + THROW(ERR, "Token length greater than 2 GB: %u64", (uint64_t)len); + } FREEMEM(ivars->text); ivars->text = (char*)MALLOCATE(len + 1); }
