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:
Justin Maggard 2017-05-17 13:54:05 -07:00
parent 4f926639b2
commit 46c692fc59
2 changed files with 27 additions and 18 deletions

View File

@ -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, vcol = get_pix(psrc, ((int32_t)rx)-half_square_width+i,
((int32_t)ry)-half_square_height+j); ((int32_t)ry)-half_square_height+j);
if(((j == 0) || (j == (half_square_height<<1)-1)) && if(((j == 0) || (j == (half_square_height<<1)-1)) &&
((i == 0) || (i == (half_square_width<<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; red /= width_scale*height_scale;
green /= width_scale*height_scale; green /= width_scale*height_scale;
blue /= width_scale*height_scale; blue /= width_scale*height_scale;
alpha /= width_scale*height_scale; alpha /= width_scale*height_scale;
/* on sature les valeurs */ /* on sature les valeurs */
red = (red > 255.0)? 255.0 : ((red < 0.0)? 0.0:red ); red = (red > 255.0)? 255.0 : ((red < 0.0)? 0.0:red );
green = (green > 255.0)? 255.0 : ((green < 0.0)? 0.0:green); 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); buf = image_save_to_jpeg_buf(pimage, &size);
if( !buf ) if( !buf )
return NULL; return NULL;
dst_file = fopen(path, "w"); dst_file = fopen(path, "w");
if( !dst_file ) if( !dst_file )
{ {
free(buf); free(buf);

View File

@ -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