summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2021-06-26 15:21:55 +0300
committerOleg Oshmyan <chortos@inbox.lv>2021-07-10 02:36:31 +0300
commit4acc1960e69fd5e86198e479088e7be50459337b (patch)
tree0ab6a74ed91fb64956f66dd578500d88cc98e9f3
parente91d3f0d17b0f0efbb8957bad1d8d6d61ae44d4b (diff)
downloadlibass-4acc1960e69fd5e86198e479088e7be50459337b.tar.bz2
libass-4acc1960e69fd5e86198e479088e7be50459337b.tar.xz
directwrite: remove arbitrary 256-char name length limit
-rw-r--r--libass/ass_directwrite.c38
-rw-r--r--libass/dwrite_c.h5
2 files changed, 32 insertions, 11 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;
}
diff --git a/libass/dwrite_c.h b/libass/dwrite_c.h
index 5612e9f..43930ca 100644
--- a/libass/dwrite_c.h
+++ b/libass/dwrite_c.h
@@ -506,8 +506,10 @@ DECLARE_INTERFACE_(IDWriteLocalizedStrings,IUnknown)
STDMETHOD(dummy1)(THIS);
STDMETHOD(dummy2)(THIS);
STDMETHOD(dummy3)(THIS);
- STDMETHOD(dummy4)(THIS);
+ STDMETHOD(GetStringLength)(THIS_
+ UINT32 index,
+ UINT32 *length) PURE;
STDMETHOD(GetString)(THIS_
UINT32 index,
WCHAR *stringBuffer,
@@ -518,6 +520,7 @@ DECLARE_INTERFACE_(IDWriteLocalizedStrings,IUnknown)
#ifdef COBJMACROS
#define IDWriteLocalizedStrings_Release(This) (This)->lpVtbl->Release(This)
#define IDWriteLocalizedStrings_GetCount(This) (This)->lpVtbl->GetCount(This)
+#define IDWriteLocalizedStrings_GetStringLength(This,index,length) (This)->lpVtbl->GetStringLength(This,index,length)
#define IDWriteLocalizedStrings_GetString(This,index,stringBuffer,size) (This)->lpVtbl->GetString(This,index,stringBuffer,size)
#endif /*COBJMACROS*/