[vlc-devel] Subtitles Failed To Get Detected For peek_Readline Not Store The Text Encoding

林作健 manjian2006 at gmail.com
Sat Nov 5 03:25:05 CET 2016


When loading a UTF-16 encoded ass subtitle on Android devices, vlc
always fails to load it.
So I take a look, and find the bug.
The bug is in subtitle_helper.h peek_Readline.
This function will always new a memory stream, and try to read from it,
then the memory stream get deleted.
The new/delete operation is why the text encoding always lost.
inline static char * peek_Readline( stream_t *p_demuxstream, uint64_t
*pi_offset )
{
    uint8_t *p_peek;
    ssize_t i_peek = vlc_stream_Peek( p_demuxstream, (const uint8_t **) &p_peek,
                                  *pi_offset + 2048 );
    if( i_peek < 0 || (uint64_t) i_peek < *pi_offset )
        return NULL;

    const uint64_t i_bufsize = (uint64_t) i_peek - *pi_offset;
    char *psz_line = NULL;

    /* Create a stream memory from that offset */
    stream_t *p_memorystream = vlc_stream_MemoryNew( p_demuxstream,
                                                     &p_peek[*pi_offset],
                                                     i_bufsize, true );
    if( p_memorystream )
    {
        psz_line = vlc_stream_ReadLine( p_memorystream );

        *pi_offset += vlc_stream_Tell( p_memorystream );
        vlc_stream_Delete( p_memorystream );
    }

    return psz_line;
}

the text encoding information stored in p_memorystream, will always
lost for deletion.

--
LINZJ


More information about the vlc-devel mailing list