Commit d2171d2b authored by Martin v. Löwis's avatar Martin v. Löwis

Overallocate target buffer for normalization more early. Fixes #834676.

Backported to 2.3.
parent 85c20a41
...@@ -84,5 +84,8 @@ def test_main(): ...@@ -84,5 +84,8 @@ def test_main():
continue continue
assert X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X), c assert X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X), c
# Check for bug 834676
normalize('NFC',u'\ud55c\uae00')
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()
...@@ -311,12 +311,14 @@ nfd_nfkd(PyObject *input, int k) ...@@ -311,12 +311,14 @@ nfd_nfkd(PyObject *input, int k)
stack[stackptr++] = *i++; stack[stackptr++] = *i++;
while(stackptr) { while(stackptr) {
Py_UNICODE code = stack[--stackptr]; Py_UNICODE code = stack[--stackptr];
if (!space) { /* Hangul Decomposition adds three characters in
space = PyString_GET_SIZE(result) + 10; a single step, so we need atleast that much room. */
if (PyUnicode_Resize(&result, space) == -1) if (space < 3) {
int newsize = PyString_GET_SIZE(result) + 10;
space += 10;
if (PyUnicode_Resize(&result, newsize) == -1)
return NULL; return NULL;
o = PyUnicode_AS_UNICODE(result) + space - 10; o = PyUnicode_AS_UNICODE(result) + newsize - space;
space = 10;
} }
/* Hangul Decomposition. */ /* Hangul Decomposition. */
if (SBase <= code && code < (SBase+SCount)) { if (SBase <= code && code < (SBase+SCount)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment