diff options
author | Oleg Oshmyan <chortos@inbox.lv> | 2021-06-26 15:21:55 +0300 |
---|---|---|
committer | Oleg Oshmyan <chortos@inbox.lv> | 2021-07-10 02:36:31 +0300 |
commit | 4acc1960e69fd5e86198e479088e7be50459337b (patch) | |
tree | 0ab6a74ed91fb64956f66dd578500d88cc98e9f3 /libass/ass_directwrite.c | |
parent | e91d3f0d17b0f0efbb8957bad1d8d6d61ae44d4b (diff) | |
download | libass-4acc1960e69fd5e86198e479088e7be50459337b.tar.bz2 libass-4acc1960e69fd5e86198e479088e7be50459337b.tar.xz |
directwrite: remove arbitrary 256-char name length limit
Diffstat (limited to 'libass/ass_directwrite.c')
-rw-r--r-- | libass/ass_directwrite.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/libass/ass_directwrite.c b/libass/ass_directwrite.c index 89e1099..deabb57 100644 --- a/libass/ass_directwrite.c +++ b/libass/ass_directwrite.c @@ -29,7 +29,6 @@ #include "ass_directwrite.h" #include "ass_utils.h" -#define NAME_MAX_LENGTH 256 #define FALLBACK_DEFAULT_FONT L"Arial" static const ASS_FontMapping font_substitutions[] = { @@ -428,19 +427,38 @@ static int encode_utf16(wchar_t *chars, uint32_t codepoint) static char *get_utf8_name(IDWriteLocalizedStrings *names, int k) { - wchar_t temp_name[NAME_MAX_LENGTH]; - HRESULT hr = IDWriteLocalizedStrings_GetString(names, k, - temp_name, - NAME_MAX_LENGTH); + wchar_t *temp_name = NULL; + char *mbName = NULL; + + UINT32 length; + HRESULT hr = IDWriteLocalizedStrings_GetStringLength(names, k, &length); if (FAILED(hr)) - return NULL; + goto cleanup; + + if (length >= (UINT32) -1 || length + (size_t) 1 > SIZE_MAX / sizeof(wchar_t)) + goto cleanup; - temp_name[NAME_MAX_LENGTH-1] = 0; - int size_needed = WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, NULL, 0, NULL, NULL); - char *mbName = (char *) malloc(size_needed); + temp_name = (wchar_t *) malloc((length + 1) * sizeof(wchar_t)); + if (!temp_name) + goto cleanup; + + hr = IDWriteLocalizedStrings_GetString(names, k, temp_name, length + 1); + if (FAILED(hr)) + goto cleanup; + + int size_needed = + WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, NULL, 0, NULL, NULL); + if (!size_needed) + goto cleanup; + + mbName = (char *) malloc(size_needed); if (!mbName) - return NULL; + goto cleanup; + WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, mbName, size_needed, NULL, NULL); + +cleanup: + free(temp_name); return mbName; } |