[vlc-commits] [Git][videolan/vlc][master] 8 commits: codec/kate: fix region leak on error
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Tue Nov 7 06:45:28 UTC 2023
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
b8b68dde by Steve Lhomme at 2023-11-06T07:32:37+01:00
codec/kate: fix region leak on error
- - - - -
dc3fe502 by Steve Lhomme at 2023-11-06T07:32:37+01:00
codec/scte27: return early on error
- - - - -
d6de10cc by Steve Lhomme at 2023-11-06T07:33:06+01:00
codec/scte27: reduce indentation
- - - - -
419258af by Steve Lhomme at 2023-11-06T07:33:06+01:00
codec/subsusf: replace while loop by a for
And continue if this not the beginning of a tag.
- - - - -
c1821c2b by Steve Lhomme at 2023-11-06T07:34:56+01:00
codec/subsusf: reduce indentation by continuing early in the loop
- - - - -
acb9dc83 by Steve Lhomme at 2023-11-06T07:38:15+01:00
codec/subsusf: factorize the code to add a region
SetupPositions() was always called before with an unmodified psz_subtitle.
- - - - -
506c75b8 by Steve Lhomme at 2023-11-06T07:38:15+01:00
codec/subsusf: remove useless variable initialization
It is always set at the beginning of each if section.
- - - - -
7d551a51 by Steve Lhomme at 2023-11-06T07:38:42+01:00
codec/dvbsub: return early if there's no region/page
- - - - -
4 changed files:
- modules/codec/dvbsub.c
- modules/codec/kate.c
- modules/codec/scte27.c
- modules/codec/subsusf.c
Changes:
=====================================
modules/codec/dvbsub.c
=====================================
@@ -1510,13 +1510,17 @@ static subpicture_t *render( decoder_t *p_dec )
i_base_y += p_sys->display.i_y;
}
+ if ( p_sys->p_page == NULL)
+ {
+ return p_spu;
+ }
+
/* Loop on region definitions */
#ifdef DEBUG_DVBSUB
- if( p_sys->p_page )
- msg_Dbg( p_dec, "rendering %i regions", p_sys->p_page->i_region_defs );
+ msg_Dbg( p_dec, "rendering %i regions", p_sys->p_page->i_region_defs );
#endif
- for( i = 0; p_sys->p_page && ( i < p_sys->p_page->i_region_defs ); i++ )
+ for( i = 0; i < p_sys->p_page->i_region_defs; i++ )
{
dvbsub_region_t *p_region;
dvbsub_regiondef_t *p_regiondef;
=====================================
modules/codec/kate.c
=====================================
@@ -910,6 +910,7 @@ static void TigerUpdateSubpicture( subpicture_t *p_subpic,
failure:
vlc_mutex_unlock( &p_sys->lock );
+ subpicture_region_Delete( p_r );
vlc_spu_regions_Clear( &p_subpic->regions );
}
=====================================
modules/codec/scte27.c
=====================================
@@ -347,58 +347,58 @@ static subpicture_t *DecodeSubtitleMessage(decoder_t *dec,
if (block_length > size)
goto error;
- if (subtitle_type == 1) {
- subpicture_region_t *region = DecodeSimpleBitmap(dec, data, block_length);
- if (!region)
- goto error;
- subpicture_t *sub = decoder_NewSubpicture(dec, NULL);
- if (!sub) {
- subpicture_region_Delete(region);
- return NULL;
- }
- vlc_tick_t frame_duration;
- switch (display_standard) {
- case 0:
- sub->i_original_picture_width = 720;
- sub->i_original_picture_height = 480;
- frame_duration = VLC_TICK_FROM_US(33367);
- break;
- case 1:
- sub->i_original_picture_width = 720;
- sub->i_original_picture_height = 576;
- frame_duration = VLC_TICK_FROM_MS(40);
- break;
- case 2:
- sub->i_original_picture_width = 1280;
- sub->i_original_picture_height = 720;
- frame_duration = VLC_TICK_FROM_US(16683);
- break;
- case 3:
- sub->i_original_picture_width = 1920;
- sub->i_original_picture_height = 1080;
- frame_duration = VLC_TICK_FROM_US(16683);
- break;
- default:
- msg_Warn(dec, "Unknown display standard");
- sub->i_original_picture_width = 0;
- sub->i_original_picture_height = 0;
- frame_duration = VLC_TICK_FROM_MS(40);
- break;
- }
- sub->b_absolute = true;
- if (!pre_clear_display)
- msg_Warn(dec, "SCTE-27 subtitles without pre_clear_display flag are not well supported");
- sub->b_ephemer = true;
- sub->i_start = date;
- sub->i_stop = date + display_duration * frame_duration;
- vlc_spu_regions_push(&sub->regions, region);
-
- return sub;
- } else {
+ if (subtitle_type != 1) {
/* Reserved */
return NULL;
}
+ subpicture_region_t *region = DecodeSimpleBitmap(dec, data, block_length);
+ if (!region)
+ goto error;
+ subpicture_t *sub = decoder_NewSubpicture(dec, NULL);
+ if (!sub) {
+ subpicture_region_Delete(region);
+ return NULL;
+ }
+ vlc_tick_t frame_duration;
+ switch (display_standard) {
+ case 0:
+ sub->i_original_picture_width = 720;
+ sub->i_original_picture_height = 480;
+ frame_duration = VLC_TICK_FROM_US(33367);
+ break;
+ case 1:
+ sub->i_original_picture_width = 720;
+ sub->i_original_picture_height = 576;
+ frame_duration = VLC_TICK_FROM_MS(40);
+ break;
+ case 2:
+ sub->i_original_picture_width = 1280;
+ sub->i_original_picture_height = 720;
+ frame_duration = VLC_TICK_FROM_US(16683);
+ break;
+ case 3:
+ sub->i_original_picture_width = 1920;
+ sub->i_original_picture_height = 1080;
+ frame_duration = VLC_TICK_FROM_US(16683);
+ break;
+ default:
+ msg_Warn(dec, "Unknown display standard");
+ sub->i_original_picture_width = 0;
+ sub->i_original_picture_height = 0;
+ frame_duration = VLC_TICK_FROM_MS(40);
+ break;
+ }
+ sub->b_absolute = true;
+ if (!pre_clear_display)
+ msg_Warn(dec, "SCTE-27 subtitles without pre_clear_display flag are not well supported");
+ sub->b_ephemer = true;
+ sub->i_start = date;
+ sub->i_stop = date + display_duration * frame_duration;
+ vlc_spu_regions_push(&sub->regions, region);
+
+ return sub;
+
error:
msg_Err(dec, "corrupted subtitle_message");
return NULL;
=====================================
modules/codec/subsusf.c
=====================================
@@ -468,11 +468,6 @@ static subpicture_region_t *CreateTextRegion( decoder_t *p_dec,
p_text_region->p_text->psz_text = psz_plaintext;
- /* Look for position arguments which may override the style-based
- * defaults.
- */
- SetupPositions( p_text_region, psz_subtitle );
-
return p_text_region;
}
@@ -811,116 +806,107 @@ static void ParseUSFString( decoder_t *p_dec,
{
decoder_sys_t *p_sys = p_dec->p_sys;
- while( *psz_subtitle )
+ for( ; *psz_subtitle; psz_subtitle++ )
{
- if( *psz_subtitle == '<' )
- {
- char *psz_end = NULL;
-
+ if( *psz_subtitle != '<' )
+ continue;
- if(( !strncasecmp( psz_subtitle, "<karaoke ", 9 )) ||
- ( !strncasecmp( psz_subtitle, "<karaoke>", 9 )))
- {
- psz_end = strcasestr( psz_subtitle, "</karaoke>" );
-
- if( psz_end )
- {
- subpicture_region_t *p_text_region;
+ char *psz_end;
+ subpicture_region_t *p_region = NULL;
- char *psz_knodes = strndup( &psz_subtitle[9], psz_end - &psz_subtitle[9] );
- if( psz_knodes )
- {
- /* remove timing <k> tags */
- char *psz_flat = CreatePlainText( psz_knodes );
- free( psz_knodes );
- if( psz_flat )
- {
- p_text_region = CreateTextRegion( p_dec,
- psz_flat,
- psz_flat,
- p_sys->i_align );
- if( p_text_region )
- {
- vlc_spu_regions_push(regions, p_text_region);
- }
- else free( psz_flat );
- }
- }
+ if(( !strncasecmp( psz_subtitle, "<karaoke ", 9 )) ||
+ ( !strncasecmp( psz_subtitle, "<karaoke>", 9 )))
+ {
+ psz_end = strcasestr( psz_subtitle, "</karaoke>" );
- psz_end += strcspn( psz_end, ">" ) + 1;
- }
- }
- else if(( !strncasecmp( psz_subtitle, "<image ", 7 )) ||
- ( !strncasecmp( psz_subtitle, "<image>", 7 )))
+ if( psz_end )
{
- subpicture_region_t *p_image_region = NULL;
-
- psz_end = strcasestr( psz_subtitle, "</image>" );
- char *psz_content = strchr( psz_subtitle, '>' );
- int i_transparent = -1;
-
- /* If a colorkey parameter is specified, then we have to map
- * that index in the picture through as transparent (it is
- * required by the USF spec but is also recommended that if the
- * creator really wants a transparent colour that they use a
- * type like PNG that properly supports it; this goes doubly
- * for VLC because the pictures are stored internally in YUV
- * and the resulting colour-matching may not produce the
- * desired results.)
- */
- char *psz_tmp = GrabAttributeValue( "colorkey", psz_subtitle );
- if( psz_tmp )
- {
- if( *psz_tmp == '#' )
- i_transparent = strtol( psz_tmp + 1, NULL, 16 ) & 0x00ffffff;
- free( psz_tmp );
- }
- if( psz_content && ( psz_content < psz_end ) )
+ char *psz_knodes = strndup( &psz_subtitle[9], psz_end - &psz_subtitle[9] );
+ if( psz_knodes )
{
- char *psz_filename = strndup( &psz_content[1], psz_end - &psz_content[1] );
- if( psz_filename )
+ /* remove timing <k> tags */
+ char *psz_flat = CreatePlainText( psz_knodes );
+ free( psz_knodes );
+ if( psz_flat )
{
- p_image_region = LoadEmbeddedImage( p_dec,
- psz_filename, i_transparent );
- free( psz_filename );
+ p_region = CreateTextRegion( p_dec,
+ psz_flat,
+ psz_flat,
+ p_sys->i_align );
+ if( !p_region )
+ free( psz_flat );
}
}
- if( psz_end ) psz_end += strcspn( psz_end, ">" ) + 1;
-
- if( p_image_region )
+ psz_end += strcspn( psz_end, ">" ) + 1;
+ }
+ }
+ else if(( !strncasecmp( psz_subtitle, "<image ", 7 )) ||
+ ( !strncasecmp( psz_subtitle, "<image>", 7 )))
+ {
+ psz_end = strcasestr( psz_subtitle, "</image>" );
+ char *psz_content = strchr( psz_subtitle, '>' );
+ int i_transparent = -1;
+
+ /* If a colorkey parameter is specified, then we have to map
+ * that index in the picture through as transparent (it is
+ * required by the USF spec but is also recommended that if the
+ * creator really wants a transparent colour that they use a
+ * type like PNG that properly supports it; this goes doubly
+ * for VLC because the pictures are stored internally in YUV
+ * and the resulting colour-matching may not produce the
+ * desired results.)
+ */
+ char *psz_tmp = GrabAttributeValue( "colorkey", psz_subtitle );
+ if( psz_tmp )
+ {
+ if( *psz_tmp == '#' )
+ i_transparent = strtol( psz_tmp + 1, NULL, 16 ) & 0x00ffffff;
+ free( psz_tmp );
+ }
+ if( psz_content && ( psz_content < psz_end ) )
+ {
+ char *psz_filename = strndup( &psz_content[1], psz_end - &psz_content[1] );
+ if( psz_filename )
{
- SetupPositions( p_image_region, psz_subtitle );
- vlc_spu_regions_push(regions, p_image_region);
+ p_region = LoadEmbeddedImage( p_dec,
+ psz_filename, i_transparent );
+ free( psz_filename );
}
}
- else
- {
- subpicture_region_t *p_text_region;
- psz_end = psz_subtitle + strlen( psz_subtitle );
+ if( psz_end ) psz_end += strcspn( psz_end, ">" ) + 1;
+ }
+ else
+ {
+ psz_end = psz_subtitle + strlen( psz_subtitle );
- char *psz_flat = CreatePlainText( psz_subtitle );
- if( psz_flat )
- {
- p_text_region = CreateTextRegion( p_dec,
- psz_subtitle,
- psz_flat,
- p_sys->i_align );
- if( p_text_region )
- {
- vlc_spu_regions_push(regions, p_text_region);
- }
- else free( psz_flat );
- }
+ char *psz_flat = CreatePlainText( psz_subtitle );
+ if( psz_flat )
+ {
+ p_region = CreateTextRegion( p_dec,
+ psz_subtitle,
+ psz_flat,
+ p_sys->i_align );
+ if( !p_region )
+ free( psz_flat );
}
- if( psz_end )
- psz_subtitle = psz_end - 1;
+ }
- psz_subtitle += strcspn( psz_subtitle, ">" );
+ if( p_region )
+ {
+ vlc_spu_regions_push(regions, p_region);
+
+ /* Look for position arguments which may override the style-based
+ * defaults.
+ */
+ SetupPositions( p_region, psz_subtitle );
}
- psz_subtitle++;
+ if( psz_end )
+ psz_subtitle = psz_end - 1;
+
+ psz_subtitle += strcspn( psz_subtitle, ">" );
}
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d6ffd5bc350707dd51f778e10e615fb7dcfce1f9...7d551a510115632f90df2a299dc1d4242bbb459e
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d6ffd5bc350707dd51f778e10e615fb7dcfce1f9...7d551a510115632f90df2a299dc1d4242bbb459e
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list