[vlc-devel] [vlc-commits] demux: mp4: handle in sample text encoding (fix #11137)
Rémi Denis-Courmont
remi at remlab.net
Thu Apr 3 20:01:06 CEST 2014
Le jeudi 3 avril 2014, 19:48:55 Francois Cartegnie a écrit :
> vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Apr 3
> 18:14:57 2014 +0200| [c3c6e9b81d34ab970ccc9bb22f960558acb31cb8] |
> committer: Francois Cartegnie
>
> demux: mp4: handle in sample text encoding (fix #11137)
>
> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c3c6e9b81d34ab970cc
> > c9bb22f960558acb31cb8
> ---
>
> modules/codec/substx3g.c | 24 ++++++++++++++++--------
> modules/demux/mp4/mp4.c | 1 -
> 2 files changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/modules/codec/substx3g.c b/modules/codec/substx3g.c
> index 4d26b9c..a735f45 100644
> --- a/modules/codec/substx3g.c
> +++ b/modules/codec/substx3g.c
> @@ -26,6 +26,7 @@
> #include <vlc_plugin.h>
> #include <vlc_codec.h>
> #include <vlc_sout.h>
> +#include <vlc_charset.h>
>
> #include "substext.h"
>
> @@ -255,14 +256,21 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t
> **pp_block ) uint8_t *p_buf = p_block->p_buffer;
>
> /* Read our raw string and create the styled segment for HTML */
> - uint16_t i_psz_length = GetWBE( p_buf );
> - char *psz_subtitle = malloc( i_psz_length + 1 );
> + uint16_t i_psz_bytelength = GetWBE( p_buf );
> + const uint8_t *p_pszstart = p_block->p_buffer + sizeof(uint16_t);
> + char *psz_subtitle;
> + if ( i_psz_bytelength > 2 &&
> + ( !memcmp( p_pszstart, "\xFE\xFF", 2 ) || !memcmp( p_pszstart,
> "\xFF\xFE", 2 ) ) + )
> + psz_subtitle = FromCharset( "UTF-16", p_pszstart, i_psz_bytelength
> ); + else
> + psz_subtitle = malloc( i_psz_bytelength + 1 );
> if ( !psz_subtitle ) return NULL;
> - memcpy( psz_subtitle, p_block->p_buffer + sizeof(uint16_t),
> i_psz_length ); - psz_subtitle[ i_psz_length ] = '\0';
> - p_buf += i_psz_length + sizeof(uint16_t);
> + memcpy( psz_subtitle, p_pszstart, i_psz_bytelength );
As pointed out on IRC, this makes no sense, not to mention that it will
overflow the heap on ASCII characters.
> + psz_subtitle[ i_psz_bytelength ] = '\0';
FromCharset() already nul-terminates. But this code makes no sense anyway.
> + p_buf += i_psz_bytelength + sizeof(uint16_t);
>
> - for( uint16_t i=0; i < i_psz_length; i++ )
> + for( uint16_t i=0; i < i_psz_bytelength; i++ )
> if ( psz_subtitle[i] == '\r' ) psz_subtitle[i] = '\n';
>
> segment_t *p_segment = calloc( 1, sizeof(segment_t) );
> @@ -317,8 +325,8 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t
> **pp_block ) while( i_cur_record++ < i_nbrecords )
> {
> if ( (size_t)(p_buf - p_block->p_buffer) < 12 ) break;
> - uint16_t i_start = __MIN( GetWBE(p_buf), i_psz_length - 1
> ); - uint16_t i_end = __MIN( GetWBE(p_buf + 2),
> i_psz_length - 1 ); + uint16_t i_start = __MIN(
> GetWBE(p_buf), i_psz_bytelength - 1 ); + uint16_t i_end =
> __MIN( GetWBE(p_buf + 2), i_psz_bytelength - 1 );
>
> segment_style_t style;
> style.i_flags = ConvertFlags( p_buf[6] );
> diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
> index e63a3f0..de1d749 100644
> --- a/modules/demux/mp4/mp4.c
> +++ b/modules/demux/mp4/mp4.c
> @@ -2001,7 +2001,6 @@ static int TrackCreateES( demux_t *p_demux,
> mp4_track_t *p_track, }
> p_track->fmt.subs.p_style = p_style;
> }
> - /* FIXME: Not true, could be UTF-16 with a Byte Order Mark
> (0xfeff) */ /* FIXME UTF-8 doesn't work here ? */
> if( p_track->b_mac_encoding )
> p_track->fmt.subs.psz_encoding = strdup( "MAC" );
>
> _______________________________________________
> vlc-commits mailing list
> vlc-commits at videolan.org
> https://mailman.videolan.org/listinfo/vlc-commits
--
Rémi Denis-Courmont
http://www.remlab.net/
More information about the vlc-devel
mailing list