1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
--- misc/icu/source/extra/scrptrun/scrptrun.cpp
+++ misc/build/icu/source/extra/scrptrun/scrptrun.cpp
@@ -150,7 +150,11 @@
// characters above it on the stack will be poped.
if (pairIndex >= 0) {
if ((pairIndex & 1) == 0) {
- parenStack[++parenSP].pairIndex = pairIndex;
+ ++parenSP;
+ int32_t nVecSize = parenStack.size();
+ if (parenSP == nVecSize)
+ parenStack.resize(nVecSize + 128);
+ parenStack[parenSP].pairIndex = pairIndex;
parenStack[parenSP].scriptCode = scriptCode;
} else if (parenSP >= 0) {
int32_t pi = pairIndex & ~1;
@@ -184,7 +188,14 @@
// pop it from the stack
if (pairIndex >= 0 && (pairIndex & 1) != 0 && parenSP >= 0) {
parenSP -= 1;
- startSP -= 1;
+ /* decrement startSP only if it is >= 0,
+ decrementing it unnecessarily will lead to memory corruption
+ while processing the above while block.
+ e.g. startSP = -4 , parenSP = -1
+ */
+ if (startSP >= 0) {
+ startSP -= 1;
+ }
}
} else {
// if the run broke on a surrogate pair,
--- misc/icu/source/extra/scrptrun/scrptrun.h
+++ misc/build/icu/source/extra/scrptrun/scrptrun.h
@@ -17,6 +17,7 @@
#include "unicode/utypes.h"
#include "unicode/uobject.h"
#include "unicode/uscript.h"
+#include <vector>
struct ScriptRecord
{
@@ -79,7 +80,7 @@
int32_t scriptEnd;
UScriptCode scriptCode;
- ParenStackEntry parenStack[128];
+ std::vector<ParenStackEntry> parenStack;
int32_t parenSP;
static int8_t highBit(int32_t value);
@@ -133,6 +134,7 @@
scriptEnd = charStart;
scriptCode = USCRIPT_INVALID_CODE;
parenSP = -1;
+ parenStack.resize(128);
}
inline void ScriptRun::reset(int32_t start, int32_t length)
|