1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-25 16:33:02 +00:00

Copy font data to ass_library instead of referencing demuxer-owned memory.

This fixes segfault when fonts are accessed after demuxer has been closed.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@25641 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
eugeni 2008-01-07 14:02:06 +00:00
parent 5ad67a4f7c
commit d2a07a1270
2 changed files with 26 additions and 3 deletions

View File

@ -195,6 +195,11 @@ int ass_read_styles(ass_track_t* track, char* fname, char* codepage);
*/ */
void ass_add_font(ass_library_t* library, char* name, char* data, int data_size); void ass_add_font(ass_library_t* library, char* name, char* data, int data_size);
/**
* \brief Remove all fonts stored in ass_library object
*/
void ass_clear_fonts(ass_library_t* library);
/** /**
* \brief Calculates timeshift from now to the start of some other subtitle event, depending on movement parameter * \brief Calculates timeshift from now to the start of some other subtitle event, depending on movement parameter
* \param track subtitle track * \param track subtitle track

View File

@ -37,6 +37,7 @@ void ass_library_done(ass_library_t* priv)
if (priv) { if (priv) {
ass_set_fonts_dir(priv, NULL); ass_set_fonts_dir(priv, NULL);
ass_set_style_overrides(priv, NULL); ass_set_style_overrides(priv, NULL);
ass_clear_fonts(priv);
free(priv); free(priv);
} }
} }
@ -84,10 +85,27 @@ static void grow_array(void **array, int nelem, size_t elsize)
void ass_add_font(ass_library_t* priv, char* name, char* data, int size) void ass_add_font(ass_library_t* priv, char* name, char* data, int size)
{ {
int idx = priv->num_fontdata;
if (!name || !data || !size)
return;
grow_array((void**)&priv->fontdata, priv->num_fontdata, sizeof(*priv->fontdata)); grow_array((void**)&priv->fontdata, priv->num_fontdata, sizeof(*priv->fontdata));
priv->fontdata[priv->num_fontdata].name = name;
priv->fontdata[priv->num_fontdata].data = data; priv->fontdata[idx].name = malloc(strlen(name));
priv->fontdata[priv->num_fontdata].size = size; strcpy(priv->fontdata[idx].name, name);
priv->fontdata[idx].data = malloc(size);
memcpy(priv->fontdata[idx].data, data, size);
priv->fontdata[idx].size = size;
priv->num_fontdata ++; priv->num_fontdata ++;
} }
void ass_clear_fonts(ass_library_t* priv)
{
int i;
for (i = 0; i < priv->num_fontdata; ++i) {
free(priv->fontdata[i].name);
free(priv->fontdata[i].data);
}
}