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
@ -730,7 +730,7 @@ image_downsize(image_s * pdest, image_s * psrc, int32_t width, int32_t height)
|
||||
{
|
||||
vcol = get_pix(psrc, ((int32_t)rx)-half_square_width+i,
|
||||
((int32_t)ry)-half_square_height+j);
|
||||
|
||||
|
||||
if(((j == 0) || (j == (half_square_height<<1)-1)) &&
|
||||
((i == 0) || (i == (half_square_width<<1)-1)))
|
||||
{
|
||||
@ -762,12 +762,12 @@ image_downsize(image_s * pdest, image_s * psrc, int32_t width, int32_t height)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
red /= width_scale*height_scale;
|
||||
green /= width_scale*height_scale;
|
||||
blue /= width_scale*height_scale;
|
||||
alpha /= width_scale*height_scale;
|
||||
|
||||
|
||||
/* on sature les valeurs */
|
||||
red = (red > 255.0)? 255.0 : ((red < 0.0)? 0.0:red );
|
||||
green = (green > 255.0)? 255.0 : ((green < 0.0)? 0.0:green);
|
||||
@ -857,7 +857,7 @@ image_save_to_jpeg_file(image_s * pimage, char * path)
|
||||
buf = image_save_to_jpeg_buf(pimage, &size);
|
||||
if( !buf )
|
||||
return NULL;
|
||||
dst_file = fopen(path, "w");
|
||||
dst_file = fopen(path, "w");
|
||||
if( !dst_file )
|
||||
{
|
||||
free(buf);
|
||||
|
37
metadata.c
37
metadata.c
@ -160,33 +160,40 @@ void
|
||||
parse_nfo(const char *path, metadata_t *m)
|
||||
{
|
||||
FILE *nfo;
|
||||
char buf[65536];
|
||||
char *buf;
|
||||
struct NameValueParserData xml;
|
||||
struct stat file;
|
||||
size_t nread;
|
||||
char *val, *val2;
|
||||
|
||||
if( stat(path, &file) != 0 ||
|
||||
file.st_size > 65536 )
|
||||
if (stat(path, &file) != 0 ||
|
||||
file.st_size > 65535)
|
||||
{
|
||||
DPRINTF(E_INFO, L_METADATA, "Not parsing very large .nfo file %s\n", path);
|
||||
return;
|
||||
}
|
||||
DPRINTF(E_DEBUG, L_METADATA, "Parsing .nfo file: %s\n", path);
|
||||
nfo = fopen(path, "r");
|
||||
if( !nfo )
|
||||
buf = calloc(1, file.st_size + 1);
|
||||
if (buf)
|
||||
return;
|
||||
nfo = fopen(path, "r");
|
||||
if (!nfo)
|
||||
{
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
nread = fread(&buf, 1, sizeof(buf), nfo);
|
||||
fclose(nfo);
|
||||
|
||||
ParseNameValue(buf, nread, &xml, 0);
|
||||
|
||||
//printf("\ttype: %s\n", GetValueFromNameValueList(&xml, "rootElement"));
|
||||
val = GetValueFromNameValueList(&xml, "title");
|
||||
if( val )
|
||||
if (val)
|
||||
{
|
||||
char *esc_tag, *title;
|
||||
val2 = GetValueFromNameValueList(&xml, "episodetitle");
|
||||
if( val2 )
|
||||
if (val2)
|
||||
xasprintf(&title, "%s - %s", val, val2);
|
||||
else
|
||||
title = strdup(val);
|
||||
@ -197,39 +204,41 @@ parse_nfo(const char *path, metadata_t *m)
|
||||
}
|
||||
|
||||
val = GetValueFromNameValueList(&xml, "plot");
|
||||
if( val ) {
|
||||
if (val)
|
||||
{
|
||||
char *esc_tag = unescape_tag(val, 1);
|
||||
m->comment = escape_tag(esc_tag, 1);
|
||||
free(esc_tag);
|
||||
}
|
||||
|
||||
val = GetValueFromNameValueList(&xml, "capturedate");
|
||||
if( val ) {
|
||||
if (val)
|
||||
{
|
||||
char *esc_tag = unescape_tag(val, 1);
|
||||
m->date = escape_tag(esc_tag, 1);
|
||||
free(esc_tag);
|
||||
}
|
||||
|
||||
val = GetValueFromNameValueList(&xml, "genre");
|
||||
if( val )
|
||||
if (val)
|
||||
{
|
||||
free(m->genre);
|
||||
char *esc_tag = unescape_tag(val, 1);
|
||||
free(m->genre);
|
||||
m->genre = escape_tag(esc_tag, 1);
|
||||
free(esc_tag);
|
||||
}
|
||||
|
||||
val = GetValueFromNameValueList(&xml, "mime");
|
||||
if( val )
|
||||
if (val)
|
||||
{
|
||||
free(m->mime);
|
||||
char *esc_tag = unescape_tag(val, 1);
|
||||
free(m->mime);
|
||||
m->mime = escape_tag(esc_tag, 1);
|
||||
free(esc_tag);
|
||||
}
|
||||
|
||||
ClearNameValueList(&xml);
|
||||
fclose(nfo);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
x
Reference in New Issue
Block a user