[vlc-devel] [PATCH] MKV SSA Subtitle Comment Stripping

Aaron Mady Aaron.Mady at DrakeSoftware.com
Sat Feb 3 20:18:45 CET 2007


This patch strips out comments within SSA subtitles contained within {
}s.  This but was currently exploited by the fansub group gg by tacking
on a 200+ character single word comment, which broke the freetype
rendering.

 

The patch updates the loop so that it keeps track of whether it's within
a comment block and only adds the characters to the subtitle string if
it is not within one.  Since this is done as a small update to the loop
that already runs through each character of the subtitle there doesn't
appear to be any noticeable performance hit, and it does fix the gg
fansub issue.

 

Aaron

 

$ svn diff

Index: modules/codec/subsdec.c

===================================================================

--- modules/codec/subsdec.c     (revision 18691)

+++ modules/codec/subsdec.c     (working copy)

@@ -473,6 +473,7 @@

 

     psz_new_subtitle = malloc( strlen( psz_buffer_sub ) + 1);

     i_text = 0;

+       vlc_bool_t b_within_comment = VLC_FALSE;

     while( psz_buffer_sub[0] != '\0' )

     {

         if( psz_buffer_sub[0] == '\\' && psz_buffer_sub[1] == 'n' )

@@ -498,12 +499,28 @@

             }

             psz_buffer_sub++;

         }

-        else

+               else if ( psz_buffer_sub[0] == '{' )

+               {

+                       b_within_comment = VLC_TRUE;

+                       psz_buffer_sub++;

+                       msg_Dbg( p_dec, "started a comment" );

+               }

+               else if ( psz_buffer_sub[0] == '}' )

+               {

+                       b_within_comment = VLC_FALSE;

+                       psz_buffer_sub++;

+                       msg_Dbg( p_dec, "ended a comment" );

+               }

+        else if ( b_within_comment == VLC_FALSE )

         {

             psz_new_subtitle[i_text] = psz_buffer_sub[0];

             i_text++;

             psz_buffer_sub++;

         }

+               else

+               {

+                       psz_buffer_sub++;

+               }

     }

     psz_new_subtitle[i_text] = '\0';

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20070203/2e571832/attachment.html>


More information about the vlc-devel mailing list