subreader.c: fix excessive memory use with some external subtitles

For each sequence of consecutive partially overlapping subtitles, the
algorithm calculating screen positions for the subtitles allocated a
2*subtitle_count*subtitle_line_count array. With some karaoke
subtitles that had lots of rapidly changing overlapping subtitles this
became large enough to use gigabytes of memory. Make the behavior
saner by limiting the line count to SUB_MAX_TEXT lines (the maximum
number of lines to show on screen at once, currently 12). This
shouldn't change the end result of the algorithm other than possibly
printing different warnings.
This commit is contained in:
Uoti Urpala 2010-01-16 12:30:34 +02:00
parent c5bd47f543
commit 6ead3e936b
1 changed files with 5 additions and 0 deletions

View File

@ -1526,6 +1526,11 @@ if ((suboverlap_enabled == 2) ||
} }
} }
/* Avoid n^2 memory use for the "placeholder" data structure
* below with subtitles that have a huge number of
* consecutive overlapping lines. */
lines_to_add = FFMIN(lines_to_add, SUB_MAX_TEXT);
// we need a structure to keep trace of the screen lines // we need a structure to keep trace of the screen lines
// used by the subs, a 'placeholder' // used by the subs, a 'placeholder'
counter = 2 * sub_to_add + 1; // the maximum number of subs derived counter = 2 * sub_to_add + 1; // the maximum number of subs derived