metadata: Reduce stack usage in nfo parsing
64KB is a bit much for a stack buffer. Use dynamic allocation instead.
This commit is contained in:
parent
4f926639b2
commit
46c692fc59
37
metadata.c
37
metadata.c
@ -160,33 +160,40 @@ void
|
|||||||
parse_nfo(const char *path, metadata_t *m)
|
parse_nfo(const char *path, metadata_t *m)
|
||||||
{
|
{
|
||||||
FILE *nfo;
|
FILE *nfo;
|
||||||
char buf[65536];
|
char *buf;
|
||||||
struct NameValueParserData xml;
|
struct NameValueParserData xml;
|
||||||
struct stat file;
|
struct stat file;
|
||||||
size_t nread;
|
size_t nread;
|
||||||
char *val, *val2;
|
char *val, *val2;
|
||||||
|
|
||||||
if( stat(path, &file) != 0 ||
|
if (stat(path, &file) != 0 ||
|
||||||
file.st_size > 65536 )
|
file.st_size > 65535)
|
||||||
{
|
{
|
||||||
DPRINTF(E_INFO, L_METADATA, "Not parsing very large .nfo file %s\n", path);
|
DPRINTF(E_INFO, L_METADATA, "Not parsing very large .nfo file %s\n", path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DPRINTF(E_DEBUG, L_METADATA, "Parsing .nfo file: %s\n", path);
|
DPRINTF(E_DEBUG, L_METADATA, "Parsing .nfo file: %s\n", path);
|
||||||
nfo = fopen(path, "r");
|
buf = calloc(1, file.st_size + 1);
|
||||||
if( !nfo )
|
if (buf)
|
||||||
return;
|
return;
|
||||||
|
nfo = fopen(path, "r");
|
||||||
|
if (!nfo)
|
||||||
|
{
|
||||||
|
free(buf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
nread = fread(&buf, 1, sizeof(buf), nfo);
|
nread = fread(&buf, 1, sizeof(buf), nfo);
|
||||||
|
fclose(nfo);
|
||||||
|
|
||||||
ParseNameValue(buf, nread, &xml, 0);
|
ParseNameValue(buf, nread, &xml, 0);
|
||||||
|
|
||||||
//printf("\ttype: %s\n", GetValueFromNameValueList(&xml, "rootElement"));
|
//printf("\ttype: %s\n", GetValueFromNameValueList(&xml, "rootElement"));
|
||||||
val = GetValueFromNameValueList(&xml, "title");
|
val = GetValueFromNameValueList(&xml, "title");
|
||||||
if( val )
|
if (val)
|
||||||
{
|
{
|
||||||
char *esc_tag, *title;
|
char *esc_tag, *title;
|
||||||
val2 = GetValueFromNameValueList(&xml, "episodetitle");
|
val2 = GetValueFromNameValueList(&xml, "episodetitle");
|
||||||
if( val2 )
|
if (val2)
|
||||||
xasprintf(&title, "%s - %s", val, val2);
|
xasprintf(&title, "%s - %s", val, val2);
|
||||||
else
|
else
|
||||||
title = strdup(val);
|
title = strdup(val);
|
||||||
@ -197,39 +204,41 @@ parse_nfo(const char *path, metadata_t *m)
|
|||||||
}
|
}
|
||||||
|
|
||||||
val = GetValueFromNameValueList(&xml, "plot");
|
val = GetValueFromNameValueList(&xml, "plot");
|
||||||
if( val ) {
|
if (val)
|
||||||
|
{
|
||||||
char *esc_tag = unescape_tag(val, 1);
|
char *esc_tag = unescape_tag(val, 1);
|
||||||
m->comment = escape_tag(esc_tag, 1);
|
m->comment = escape_tag(esc_tag, 1);
|
||||||
free(esc_tag);
|
free(esc_tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
val = GetValueFromNameValueList(&xml, "capturedate");
|
val = GetValueFromNameValueList(&xml, "capturedate");
|
||||||
if( val ) {
|
if (val)
|
||||||
|
{
|
||||||
char *esc_tag = unescape_tag(val, 1);
|
char *esc_tag = unescape_tag(val, 1);
|
||||||
m->date = escape_tag(esc_tag, 1);
|
m->date = escape_tag(esc_tag, 1);
|
||||||
free(esc_tag);
|
free(esc_tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
val = GetValueFromNameValueList(&xml, "genre");
|
val = GetValueFromNameValueList(&xml, "genre");
|
||||||
if( val )
|
if (val)
|
||||||
{
|
{
|
||||||
free(m->genre);
|
|
||||||
char *esc_tag = unescape_tag(val, 1);
|
char *esc_tag = unescape_tag(val, 1);
|
||||||
|
free(m->genre);
|
||||||
m->genre = escape_tag(esc_tag, 1);
|
m->genre = escape_tag(esc_tag, 1);
|
||||||
free(esc_tag);
|
free(esc_tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
val = GetValueFromNameValueList(&xml, "mime");
|
val = GetValueFromNameValueList(&xml, "mime");
|
||||||
if( val )
|
if (val)
|
||||||
{
|
{
|
||||||
free(m->mime);
|
|
||||||
char *esc_tag = unescape_tag(val, 1);
|
char *esc_tag = unescape_tag(val, 1);
|
||||||
|
free(m->mime);
|
||||||
m->mime = escape_tag(esc_tag, 1);
|
m->mime = escape_tag(esc_tag, 1);
|
||||||
free(esc_tag);
|
free(esc_tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearNameValueList(&xml);
|
ClearNameValueList(&xml);
|
||||||
fclose(nfo);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user