Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39493e4

Browse files
committed
Cope with more than 64K phrases in a thesaurus dictionary.
dict_thesaurus stored phrase IDs in uint16 fields, so it would get confusedand even crash if there were more than 64K entries in the configurationfile. It turns out to be basically free to widen the phrase IDs to uint32,so let's just do so.This was complained of some time ago by David Boutin (in bug #7793);he later submitted an informal patch but it was never acted on.We now have another complaint (bug #11901 from Luc Ouellette) so it'stime to make something happen.This is basically Boutin's patch, but for future-proofing I also added adefense against too many words per phrase. Note that we don't need anyexplicit defense against overflow of the uint32 counters, since before thathappens we'd hit array allocation sizes that repalloc rejects.Back-patch to all supported branches because of the crash risk.
1 parent83c7bfb commit39493e4

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

‎src/backend/tsearch/dict_thesaurus.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
typedefstructLexemeInfo
3131
{
32-
uint16idsubst;/* entry's number in DictThesaurus->subst */
32+
uint32idsubst;/* entry's number in DictThesaurus->subst */
3333
uint16posinsubst;/* pos info in entry */
3434
uint16tnvariant;/* total num lexemes in one variant */
3535
structLexemeInfo*nextentry;
@@ -69,7 +69,7 @@ typedef struct
6969

7070

7171
staticvoid
72-
newLexeme(DictThesaurus*d,char*b,char*e,uint16idsubst,uint16posinsubst)
72+
newLexeme(DictThesaurus*d,char*b,char*e,uint32idsubst,uint16posinsubst)
7373
{
7474
TheLexeme*ptr;
7575

@@ -103,7 +103,7 @@ newLexeme(DictThesaurus *d, char *b, char *e, uint16 idsubst, uint16 posinsubst)
103103
}
104104

105105
staticvoid
106-
addWrd(DictThesaurus*d,char*b,char*e,uint16idsubst,uint16nwrd,uint16posinsubst,booluseasis)
106+
addWrd(DictThesaurus*d,char*b,char*e,uint32idsubst,uint16nwrd,uint16posinsubst,booluseasis)
107107
{
108108
staticintnres=0;
109109
staticintntres=0;
@@ -144,7 +144,6 @@ addWrd(DictThesaurus *d, char *b, char *e, uint16 idsubst, uint16 nwrd, uint16 p
144144
ntres *=2;
145145
ptr->res= (TSLexeme*)repalloc(ptr->res,sizeof(TSLexeme)*ntres);
146146
}
147-
148147
}
149148

150149
ptr->res[nres].lexeme=palloc(e-b+1);
@@ -169,7 +168,7 @@ static void
169168
thesaurusRead(char*filename,DictThesaurus*d)
170169
{
171170
tsearch_readline_statetrst;
172-
uint16idsubst=0;
171+
uint32idsubst=0;
173172
booluseasis= false;
174173
char*line;
175174

@@ -185,8 +184,8 @@ thesaurusRead(char *filename, DictThesaurus *d)
185184
char*ptr;
186185
intstate=TR_WAITLEX;
187186
char*beginwrd=NULL;
188-
uint16posinsubst=0;
189-
uint16nwrd=0;
187+
uint32posinsubst=0;
188+
uint32nwrd=0;
190189

191190
ptr=line;
192191

@@ -287,6 +286,16 @@ thesaurusRead(char *filename, DictThesaurus *d)
287286
(errcode(ERRCODE_CONFIG_FILE_ERROR),
288287
errmsg("unexpected end of line")));
289288

289+
/*
290+
* Note: currently, tsearch_readline can't return lines exceeding 4KB,
291+
* so overflow of the word counts is impossible. But that may not
292+
* always be true, so let's check.
293+
*/
294+
if (nwrd!= (uint16)nwrd||posinsubst!= (uint16)posinsubst)
295+
ereport(ERROR,
296+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
297+
errmsg("too many lexemes in thesaurus entry")));
298+
290299
pfree(line);
291300
}
292301

@@ -671,7 +680,7 @@ findTheLexeme(DictThesaurus *d, char *lexeme)
671680
}
672681

673682
staticbool
674-
matchIdSubst(LexemeInfo*stored,uint16idsubst)
683+
matchIdSubst(LexemeInfo*stored,uint32idsubst)
675684
{
676685
boolres= true;
677686

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp