Reactos

[RICHED20] Fix assert in editpad due to excessive tab count (#6976)

* https://jira.reactos.org/browse/CORE-8452

* Cherry pick this Wine commit into ReactOS:
https://gitlab.winehq.org/wine/wine/-/commit/7b2ff977739df25252d46552d2447af50c23040e

authored by

Doug Lyons and committed by
GitHub
40955b44 ecb5cae4

+31 -2
+2 -2
dll/win32/riched20/para.c
··· 494 494 COPY_FIELD(PFM_ALIGNMENT, wAlignment); 495 495 if (dwMask & PFM_TABSTOPS) 496 496 { 497 - para->fmt.cTabCount = pFmt->cTabCount; 498 - memcpy(para->fmt.rgxTabs, pFmt->rgxTabs, pFmt->cTabCount*sizeof(LONG)); 497 + para->fmt.cTabCount = max(0, min(pFmt->cTabCount, MAX_TAB_STOPS)); /* Clamp between 0 and MAX_TAB_STOPS */ 498 + memcpy(para->fmt.rgxTabs, pFmt->rgxTabs, para->fmt.cTabCount*sizeof(LONG)); 499 499 } 500 500 501 501 #define EFFECTS_MASK (PFM_RTLPARA|PFM_KEEP|PFM_KEEPNEXT|PFM_PAGEBREAKBEFORE| \
+29
modules/rostests/winetests/riched20/editor.c
··· 8642 8642 SendMessageW(richedit, EM_GETPARAFORMAT, 0, (LPARAM)&pf); 8643 8643 ok(pf.wAlignment == align_mask[i], "got %d expect %d\n", pf.wAlignment, align_mask[i]); 8644 8644 8645 + /* Test out of bounds tab count */ 8646 + pf.dwMask = PFM_TABSTOPS; 8647 + pf.cTabCount = -25000; 8648 + SendMessageW(richedit, EM_SETPARAFORMAT, 0, (LPARAM)&pf); 8649 + ok(pf.cTabCount == -25000, "Got %d\n", pf.cTabCount); 8650 + SendMessageW(richedit, EM_GETPARAFORMAT, 0, (LPARAM)&pf); 8651 + ok(pf.cTabCount == 0, "Got %d\n", pf.cTabCount); 8652 + pf.dwMask = PFM_TABSTOPS; 8653 + pf.cTabCount = 25000; 8654 + SendMessageW(richedit, EM_SETPARAFORMAT, 0, (LPARAM)&pf); 8655 + ok(pf.cTabCount == 25000, "Got %d\n", pf.cTabCount); 8656 + SendMessageW(richedit, EM_GETPARAFORMAT, 0, (LPARAM)&pf); 8657 + ok(pf.cTabCount == 32, "Got %d\n", pf.cTabCount); 8658 + pf.dwMask = PFM_TABSTOPS; 8659 + pf.cTabCount = 32; 8660 + SendMessageW(richedit, EM_SETPARAFORMAT, 0, (LPARAM)&pf); 8661 + SendMessageW(richedit, EM_GETPARAFORMAT, 0, (LPARAM)&pf); 8662 + ok(pf.cTabCount == 32, "Got %d\n", pf.cTabCount); 8663 + pf.dwMask = PFM_TABSTOPS; 8664 + pf.cTabCount = 33; 8665 + SendMessageW(richedit, EM_SETPARAFORMAT, 0, (LPARAM)&pf); 8666 + SendMessageW(richedit, EM_GETPARAFORMAT, 0, (LPARAM)&pf); 8667 + ok(pf.cTabCount == 32, "Got %d\n", pf.cTabCount); 8668 + pf.dwMask = PFM_TABSTOPS; 8669 + pf.cTabCount = 1; 8670 + SendMessageW(richedit, EM_SETPARAFORMAT, 0, (LPARAM)&pf); 8671 + SendMessageW(richedit, EM_GETPARAFORMAT, 0, (LPARAM)&pf); 8672 + ok(pf.cTabCount == 1, "Got %d\n", pf.cTabCount); 8673 + 8645 8674 DestroyWindow(richedit); 8646 8675 } 8647 8676