fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / external / hunspell / hunspell-1.3.3-rhbz1261421.patch
blob4354dd00b37d9a27a7ec70e22524d892c723a4e0
1 From 97e079a23d459aeb6e64435350d7710c90dbca85 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
3 Date: Fri, 11 Sep 2015 13:28:52 +0100
4 Subject: [PATCH] Resolves: rhbz#1261421 crash on mashing hangul korean
5 keyboard
7 ---
8 src/hunspell/hunspell.cxx | 69 +++++++++++++++++++++++++++++++++++------------
9 src/hunspell/hunspell.hxx | 4 ++-
10 src/hunspell/replist.cxx | 18 ++++++++++---
11 src/hunspell/replist.hxx | 2 ++
12 src/tools/hunspell.cxx | 2 +-
13 6 files changed, 78 insertions(+), 24 deletions(-)
15 diff --git a/src/hunspell/hunspell.cxx b/src/hunspell/hunspell.cxx
16 index 7fae54b..d8ef357 100644
17 --- misc/hunspell-1.3.3/src/hunspell/hunspell.cxx
18 +++ misc/build/hunspell-1.3.3/src/hunspell/hunspell.cxx
19 @@ -12,6 +12,7 @@
20 #endif
21 #include "csutil.hxx"
23 +#include <limits>
24 #include <string>
26 Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key)
27 @@ -349,8 +350,13 @@ int Hunspell::spell(const char * word, int * info, char ** root)
29 // input conversion
30 RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
31 - if (rl && rl->conv(word, wspace)) wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
32 - else wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
33 + int convstatus = rl ? rl->conv(word, wspace, MAXWORDUTF8LEN) : 0;
34 + if (convstatus < 0)
35 + return 0;
36 + else if (convstatus > 0)
37 + wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
38 + else
39 + wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
41 if (wl == 0 || maxdic == 0) return 1;
42 if (root) *root = NULL;
43 @@ -702,8 +708,13 @@ int Hunspell::suggest(char*** slst, const char * word)
45 // input conversion
46 RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
47 - if (rl && rl->conv(word, wspace)) wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
48 - else wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
49 + int convstatus = rl ? rl->conv(word, wspace, MAXWORDUTF8LEN) : 0;
50 + if (convstatus < 0)
51 + return 0;
52 + else if (convstatus > 0)
53 + wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
54 + else
55 + wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
57 if (wl == 0) return 0;
58 int ns = 0;
59 @@ -1020,7 +1031,7 @@ int Hunspell::suggest(char*** slst, const char * word)
60 // output conversion
61 rl = (pAMgr) ? pAMgr->get_oconvtable() : NULL;
62 for (int j = 0; rl && j < ns; j++) {
63 - if (rl->conv((*slst)[j], wspace)) {
64 + if (rl->conv((*slst)[j], wspace, MAXWORDUTF8LEN) > 0) {
65 free((*slst)[j]);
66 (*slst)[j] = mystrdup(wspace);
68 @@ -1395,8 +1406,13 @@ int Hunspell::analyze(char*** slst, const char * word)
70 // input conversion
71 RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
72 - if (rl && rl->conv(word, wspace)) wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
73 - else wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
74 + int convstatus = rl ? rl->conv(word, wspace, MAXWORDUTF8LEN) : 0;
75 + if (convstatus < 0)
76 + return 0;
77 + else if (convstatus > 0)
78 + wl = cleanword2(cw, wspace, unicw, &nc, &captype, &abbv);
79 + else
80 + wl = cleanword2(cw, word, unicw, &nc, &captype, &abbv);
82 if (wl == 0) {
83 if (abbv) {
84 @@ -1684,12 +1700,16 @@ int Hunspell::get_langnum() const
85 return langnum;
88 -int Hunspell::input_conv(const char * word, char * dest)
89 +int Hunspell::input_conv(const char * word, char * dest, size_t destsize)
91 RepList * rl = (pAMgr) ? pAMgr->get_iconvtable() : NULL;
92 - return (rl && rl->conv(word, dest));
93 + return (rl && rl->conv(word, dest, destsize) > 0);
96 +int Hunspell::input_conv(const char * word, char * dest)
98 + return input_conv(word, dest, std::numeric_limits<std::size_t>::max());
101 // return the beginning of the element (attr == NULL) or the attribute
102 const char * Hunspell::get_xml_pos(const char * s, const char * attr)
103 diff --git a/src/hunspell/hunspell.hxx b/src/hunspell/hunspell.hxx
104 index e62f0dd..0b5ad2e 100644
105 --- misc/hunspell-1.3.3/src/hunspell/hunspell.hxx
106 +++ misc/build/hunspell-1.3.3/src/hunspell/hunspell.hxx
107 @@ -226,7 +226,9 @@ public:
109 /* need for putdic */
110 int input_conv(const char * word, char * dest);
112 + // ^^-deprecated, use this-vv"
113 + int input_conv(const char * word, char * dest, size_t destsize);
115 /* experimental and deprecated functions */
117 #ifdef HUNSPELL_EXPERIMENTAL
118 diff --git a/src/hunspell/replist.cxx b/src/hunspell/replist.cxx
119 index b9b1255..bac3e06 100644
120 --- misc/hunspell-1.3.3/src/hunspell/replist.cxx
121 +++ misc/build/hunspell-1.3.3/src/hunspell/replist.cxx
122 @@ -74,6 +74,7 @@
123 #include <stdlib.h>
124 #include <string.h>
125 #include <stdio.h>
126 +#include <limits>
128 #include "replist.hxx"
129 #include "csutil.hxx"
130 @@ -139,19 +140,30 @@ int RepList::add(char * pat1, char * pat2) {
131 return 0;
134 -int RepList::conv(const char * word, char * dest) {
135 +int RepList::conv(const char * word, char * dest, size_t destsize) {
136 int stl = 0;
137 int change = 0;
138 for (size_t i = 0; i < strlen(word); i++) {
139 int n = near(word + i);
140 int l = match(word + i, n);
141 if (l) {
142 + size_t replen = strlen(dat[n]->pattern2);
143 + if (stl+replen >= destsize)
144 + return -1;
145 strcpy(dest + stl, dat[n]->pattern2);
146 - stl += strlen(dat[n]->pattern2);
147 + stl += replen;
148 i += l - 1;
149 change = 1;
150 - } else dest[stl++] = word[i];
151 + } else {
152 + if (stl+1 >= destsize)
153 + return -1;
154 + dest[stl++] = word[i];
157 dest[stl] = '\0';
158 return change;
161 +int RepList::conv(const char * word, char * dest) {
162 + return conv(word, dest, std::numeric_limits<std::size_t>::max());
164 diff --git a/src/hunspell/replist.hxx b/src/hunspell/replist.hxx
165 index 1e3d6e4..e418298 100644
166 --- misc/hunspell-1.3.3/src/hunspell/replist.hxx
167 +++ misc/build/hunspell-1.3.3/src/hunspell/replist.hxx
168 @@ -99,5 +99,7 @@ public:
169 int near(const char * word);
170 int match(const char * word, int n);
171 int conv(const char * word, char * dest);
172 + // ^^-deprecated, use this-vv"
173 + int conv(const char * word, char * dest, size_t destsize);
175 #endif
176 diff --git a/src/tools/hunspell.cxx b/src/tools/hunspell.cxx
177 index 6124ac4..1b50fe1 100644
178 --- misc/hunspell-1.3.3/src/tools/hunspell.cxx
179 +++ misc/build/hunspell-1.3.3/src/tools/hunspell.cxx
180 @@ -524,7 +524,7 @@ int putdic(char * word, Hunspell * pMS)
182 word = chenc(word, ui_enc, dic_enc[0]);
184 - if(pMS->input_conv(word, buf)) word = buf;
185 + if(pMS->input_conv(word, buf, MAXLNLEN)) word = buf;
187 int ret;
190 2.4.0