[vlc-devel] Security: Subtitle StripTags heap corruption, potentially exploitable. Patch included

Harry Sintonen sintonen at iki.fi
Sun Jan 16 11:58:17 CET 2011


I ran into some corrupt mkv that'd crash vlc. Debugging revealed an issue 
in StripTags() function: It can run past the input string termination 
resulting in a heap corruption.

Assuming the input string contains a '<' char but doesn't include the 
terminating '>' the routine will run past end of the string termination. 
It happens because of psz_subtitle += strcspn( psz_subtitle, ">" ); in 
combination with psz_subtitle++; will advance psz_subtitle past the string 
termination. Bytes after the string termination will be copied to the 
destination buffer, smashing the heap.

It is trivial to test this issue by calling StripTags with a specially 
crafted input string such as "<foo\0crashme" (use valgrind or a similar 
tool to track the corruption).

Considering the advanced state of heap corruption exploits these days this 
issue should be considered exploitable security vulnerability. Address 
space layout randomization or non-executable stack only slows down a 
determined attacker.

Diff fixing the issue follows:

diff --git a/modules/codec/subsdec.c b/modules/codec/subsdec.c
index 22c951e..d0beae8 100644
--- a/modules/codec/subsdec.c
+++ b/modules/codec/subsdec.c
@@ -640,6 +640,9 @@ static char *StripTags( char *psz_subtitle )
              *psz_text++ = *psz_subtitle;

+        /* Security fix: Account for the case where input ends early */
+        if( *psz_subtitle == '\0' ) break;
      *psz_text = '\0';
diff --git a/modules/codec/subsusf.c b/modules/codec/subsusf.c
index c69c454..3886c52 100644
--- a/modules/codec/subsusf.c
+++ b/modules/codec/subsusf.c
@@ -1072,6 +1072,9 @@ static char *StripTags( char *psz_subtitle )
              *psz_text++ = *psz_subtitle;

+        /* Security fix: Account for the case where input ends early */
+        if( *psz_subtitle == '\0' ) break;
      *psz_text = '\0';

Note that the fix is conservative: The check for early termination could 
be located just after the psz_subtitle += strcspn( psz_subtitle, ">" ); as 
well. However this would make it easier to reintroduce the bug later on 
due to forgetting to check for the termination when needed. I think it's 
more sensible to have a more broad generic check to avoid this.


l=2001;main(i){float o,O,_,I,D;for(;O=I=l/571.-1.75,l;)for(putchar(--l%80?
("  Harry 'Piru' Sintonen <sintonen at iki.fi> http://www.iki.fi/sintonen");}

More information about the vlc-devel mailing list