diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/tsearch/dict_thesaurus.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/backend/tsearch/dict_thesaurus.c b/src/backend/tsearch/dict_thesaurus.c index 7ff28b80b36..b152867107b 100644 --- a/src/backend/tsearch/dict_thesaurus.c +++ b/src/backend/tsearch/dict_thesaurus.c @@ -29,7 +29,7 @@ typedef struct LexemeInfo { - uint16 idsubst; /* entry's number in DictThesaurus->subst */ + uint32 idsubst; /* entry's number in DictThesaurus->subst */ uint16 posinsubst; /* pos info in entry */ uint16 tnvariant; /* total num lexemes in one variant */ struct LexemeInfo *nextentry; @@ -69,7 +69,7 @@ typedef struct static void -newLexeme(DictThesaurus *d, char *b, char *e, uint16 idsubst, uint16 posinsubst) +newLexeme(DictThesaurus *d, char *b, char *e, uint32 idsubst, uint16 posinsubst) { TheLexeme *ptr; @@ -103,7 +103,7 @@ newLexeme(DictThesaurus *d, char *b, char *e, uint16 idsubst, uint16 posinsubst) } static void -addWrd(DictThesaurus *d, char *b, char *e, uint16 idsubst, uint16 nwrd, uint16 posinsubst, bool useasis) +addWrd(DictThesaurus *d, char *b, char *e, uint32 idsubst, uint16 nwrd, uint16 posinsubst, bool useasis) { static int nres = 0; static int ntres = 0; @@ -144,7 +144,6 @@ addWrd(DictThesaurus *d, char *b, char *e, uint16 idsubst, uint16 nwrd, uint16 p ntres *= 2; ptr->res = (TSLexeme *) repalloc(ptr->res, sizeof(TSLexeme) * ntres); } - } ptr->res[nres].lexeme = palloc(e - b + 1); @@ -169,7 +168,7 @@ static void thesaurusRead(char *filename, DictThesaurus *d) { tsearch_readline_state trst; - uint16 idsubst = 0; + uint32 idsubst = 0; bool useasis = false; char *line; @@ -185,8 +184,8 @@ thesaurusRead(char *filename, DictThesaurus *d) char *ptr; int state = TR_WAITLEX; char *beginwrd = NULL; - uint16 posinsubst = 0; - uint16 nwrd = 0; + uint32 posinsubst = 0; + uint32 nwrd = 0; ptr = line; @@ -287,6 +286,16 @@ thesaurusRead(char *filename, DictThesaurus *d) (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("unexpected end of line"))); + /* + * Note: currently, tsearch_readline can't return lines exceeding 4KB, + * so overflow of the word counts is impossible. But that may not + * always be true, so let's check. + */ + if (nwrd != (uint16) nwrd || posinsubst != (uint16) posinsubst) + ereport(ERROR, + (errcode(ERRCODE_CONFIG_FILE_ERROR), + errmsg("too many lexemes in thesaurus entry"))); + pfree(line); } @@ -671,7 +680,7 @@ findTheLexeme(DictThesaurus *d, char *lexeme) } static bool -matchIdSubst(LexemeInfo *stored, uint16 idsubst) +matchIdSubst(LexemeInfo *stored, uint32 idsubst) { bool res = true; |