OLD | NEW |
1 Index: source/test/cintltst/cbiditst.c | 1 diff --git a/source/common/ubidi.c b/source/common/ubidi.c |
2 =================================================================== | 2 index 8c0d64b..e773de7 100644 |
3 --- source/test/cintltst/cbiditst.c» (revision 36303) | 3 --- a/source/common/ubidi.c |
4 +++ source/test/cintltst/cbiditst.c» (revision 36304) | 4 +++ b/source/common/ubidi.c |
5 @@ -87,6 +87,8 @@ | 5 @@ -1,7 +1,7 @@ |
| 6 /* |
| 7 ****************************************************************************** |
| 8 * |
| 9 -* Copyright (C) 1999-2014, International Business Machines |
| 10 +* Copyright (C) 1999-2015, International Business Machines |
| 11 * Corporation and others. All Rights Reserved. |
| 12 * |
| 13 ****************************************************************************** |
| 14 @@ -2340,7 +2340,7 @@ setParaSuccess(UBiDi *pBiDi) { |
| 15 static void |
| 16 setParaRunsOnly(UBiDi *pBiDi, const UChar *text, int32_t length, |
| 17 UBiDiLevel paraLevel, UErrorCode *pErrorCode) { |
| 18 - void *runsOnlyMemory; |
| 19 + void *runsOnlyMemory = NULL; |
| 20 int32_t *visualMap; |
| 21 UChar *visualText; |
| 22 int32_t saveLength, saveTrailingWSStart; |
| 23 @@ -2514,12 +2514,13 @@ setParaRunsOnly(UBiDi *pBiDi, const UChar *text, int32_t
length, |
| 24 } |
| 25 uprv_memcpy(pBiDi->levels, saveLevels, saveLength*sizeof(UBiDiLevel)); |
| 26 pBiDi->trailingWSStart=saveTrailingWSStart; |
| 27 - /* free memory for mapping table and visual text */ |
| 28 - uprv_free(runsOnlyMemory); |
| 29 if(pBiDi->runCount>1) { |
| 30 pBiDi->direction=UBIDI_MIXED; |
| 31 } |
| 32 cleanup3: |
| 33 + /* free memory for mapping table and visual text */ |
| 34 + uprv_free(runsOnlyMemory); |
| 35 + |
| 36 pBiDi->reorderingMode=UBIDI_REORDER_RUNS_ONLY; |
| 37 } |
6 | 38 |
7 static void doTailTest(void); | |
8 | |
9 +static void testBracketOverflow(void); | |
10 + | |
11 /* new BIDI API */ | |
12 static void testReorderingMode(void); | |
13 static void testReorderRunsOnly(void); | |
14 @@ -133,6 +135,7 @@ | |
15 addTest(root, testClassOverride, "complex/bidi/TestClassOverride"); | |
16 addTest(root, testGetBaseDirection, "complex/bidi/testGetBaseDirection"); | |
17 addTest(root, testContext, "complex/bidi/testContext"); | |
18 + addTest(root, testBracketOverflow, "complex/bidi/TestBracketOverflow"); | |
19 | |
20 addTest(root, doArabicShapingTest, "complex/arabic-shaping/ArabicShapingTes
t"); | |
21 addTest(root, doLamAlefSpecialVLTRArabicShapingTest, "complex/arabic-shapin
g/lamalef"); | |
22 @@ -4896,3 +4899,25 @@ | |
23 | |
24 log_verbose("\nExiting TestContext \n\n"); | |
25 } | |
26 + | |
27 +/* Ticket#11054 ubidi_setPara crash with heavily nested brackets */ | |
28 +static void | |
29 +testBracketOverflow(void) { | |
30 + static const char* TEXT = "(((((((((((((((((((((((((((((((((((((((((a)(A)))
))))))))))))))))))))))))))))))))))))))"; | |
31 + UErrorCode status = U_ZERO_ERROR; | |
32 + UBiDi* bidi; | |
33 + UChar src[100]; | |
34 + UChar dest[100]; | |
35 + int32_t len; | |
36 + | |
37 + bidi = ubidi_open(); | |
38 + len = uprv_strlen(TEXT); | |
39 + pseudoToU16(len, TEXT, src); | |
40 + ubidi_setPara(bidi, src, len, UBIDI_DEFAULT_LTR , NULL, &status); | |
41 + if (U_FAILURE(status)) { | |
42 + log_err("setPara failed with heavily nested brackets - %s", u_errorName
(status)); | |
43 + } | |
44 + | |
45 + ubidi_close(bidi); | |
46 +} | |
47 + | |
48 Index: source/common/ubidiimp.h | |
49 =================================================================== | |
50 --- source/common/ubidiimp.h (revision 36303) | |
51 +++ source/common/ubidiimp.h (revision 36304) | |
52 @@ -173,7 +173,7 @@ | |
53 /* array of opening entries which should be enough in most cases; no malloc
() */ | |
54 Opening simpleOpenings[SIMPLE_OPENINGS_SIZE]; | |
55 Opening *openings; /* pointer to current array of entries
*/ | |
56 - int32_t openingsSize; /* number of allocated entries */ | |
57 + int32_t openingsCount; /* number of allocated entries */ | |
58 int32_t isoRunLast; /* index of last used entry */ | |
59 /* array of nested isolated sequence entries; can never excess UBIDI_MAX_EX
PLICIT_LEVEL | |
60 + 1 for index 0, + 1 for before the first isolated sequence */ | |
61 Index: source/common/ubidi.c | |
62 =================================================================== | |
63 --- source/common/ubidi.c (revision 36303) | |
64 +++ source/common/ubidi.c (revision 36304) | |
65 @@ -679,10 +679,10 @@ | |
66 bd->isoRuns[0].contextPos=0; | |
67 if(pBiDi->openingsMemory) { | |
68 bd->openings=pBiDi->openingsMemory; | |
69 - bd->openingsSize=pBiDi->openingsSize; | |
70 + bd->openingsCount=pBiDi->openingsSize / sizeof(Opening); | |
71 } else { | |
72 bd->openings=bd->simpleOpenings; | |
73 - bd->openingsSize=SIMPLE_OPENINGS_SIZE; | |
74 + bd->openingsCount=SIMPLE_OPENINGS_SIZE; | |
75 } | |
76 bd->isNumbersSpecial=bd->pBiDi->reorderingMode==UBIDI_REORDER_NUMBERS_SPECI
AL || | |
77 bd->pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_FOR_N
UMBERS_SPECIAL; | |
78 @@ -743,7 +743,7 @@ | |
79 bracketAddOpening(BracketData *bd, UChar match, int32_t position) { | |
80 IsoRun *pLastIsoRun=&bd->isoRuns[bd->isoRunLast]; | |
81 Opening *pOpening; | |
82 - if(pLastIsoRun->limit>=bd->openingsSize) { /* no available new entry */ | |
83 + if(pLastIsoRun->limit>=bd->openingsCount) { /* no available new entry */ | |
84 UBiDi *pBiDi=bd->pBiDi; | |
85 if(!getInitialOpeningsMemory(pBiDi, pLastIsoRun->limit * 2)) | |
86 return FALSE; | |
87 @@ -751,7 +751,7 @@ | |
88 uprv_memcpy(pBiDi->openingsMemory, bd->simpleOpenings, | |
89 SIMPLE_OPENINGS_SIZE * sizeof(Opening)); | |
90 bd->openings=pBiDi->openingsMemory; /* may have changed */ | |
91 - bd->openingsSize=pBiDi->openingsSize; | |
92 + bd->openingsCount=pBiDi->openingsSize / sizeof(Opening); | |
93 } | |
94 pOpening=&bd->openings[pLastIsoRun->limit]; | |
95 pOpening->position=position; | |
OLD | NEW |