[vlc-devel] [PATCH 2/2] subtitle: remove hand-coded conversion

RĂ©mi Denis-Courmont remi at remlab.net
Sun Nov 12 12:42:10 CET 2017


This fixes an invalid free on error.
---
 modules/demux/subtitle.c | 28 +++++-----------------------
 1 file changed, 5 insertions(+), 23 deletions(-)

diff --git a/modules/demux/subtitle.c b/modules/demux/subtitle.c
index cfbe106d1f..b6599c8269 100644
--- a/modules/demux/subtitle.c
+++ b/modules/demux/subtitle.c
@@ -426,29 +426,11 @@ static int Open ( vlc_object_t *p_this )
     {
         if( i_peek > 16 )
         {
-            vlc_iconv_t handle = vlc_iconv_open( "UTF-8", psz_bom );
-            if( handle )
-            {
-                char *p_outbuf = malloc( i_peek );
-                if( p_outbuf )
-                {
-                    const char *p_inbuf = (const char *) p_peek;
-                    char *psz_converted = p_outbuf;
-                    const size_t i_outbuf_size = i_peek;
-                    size_t i_inbuf_remain = i_peek;
-                    size_t i_outbuf_remain = i_peek;
-                    if ( VLC_ICONV_ERR != vlc_iconv( handle,
-                                                     &p_inbuf, &i_inbuf_remain,
-                                                     &p_outbuf, &i_outbuf_remain ) )
-                    {
-                        p_probestream = vlc_stream_MemoryNew( p_demux, (uint8_t *) psz_converted,
-                                                            i_outbuf_size - i_outbuf_remain,
-                                                            false ); /* free p_outbuf on release */
-                    }
-                    else free( p_outbuf );
-                }
-                vlc_iconv_close( handle );
-            }
+            char *p_outbuf = FromCharset( psz_bom, p_peek, i_peek );
+            if( p_outbuf != NULL )
+                p_probestream = vlc_stream_MemoryNew( p_demux, (uint8_t *)p_outbuf,
+                                                      strlen( p_outbuf ),
+                                                      false ); /* free p_outbuf on release */
         }
     }
     else
-- 
2.15.0



More information about the vlc-devel mailing list