[vlc-commits] [Git][videolan/vlc][master] 16 commits: video_chroma: copy: fix leak on error
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Thu Sep 21 09:08:01 UTC 2023
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
69811fa3 by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
video_chroma: copy: fix leak on error
- - - - -
a2f6acca by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
mux: mp4: reindent weird block
- - - - -
725d3dd4 by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
mux: mp4: handle error code in BlockDequeue
- - - - -
6e5eae8a by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
mux: libmp4mux: add missing allocation check
- - - - -
9b9d1daa by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
stream_out: rtp: add missing allocation check
- - - - -
0982a063 by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
demux: ogg: use early return
- - - - -
7d6ff020 by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
demux: ogg: add missing allocation check
- - - - -
77ed82a5 by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
vlc_input: use early return
- - - - -
0e3741a6 by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
vlc_input: handle strdup failure
If the string duplication failed, we don't want to return a
non-identical seekpoint and should prefer to signal that allocation as a
whole failed.
- - - - -
0380015e by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
demux: mp4: check p_sys->p_title early
We only need to check p_sys->p_title once and not at every iteration of
the loop.
- - - - -
e82c7160 by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
demux: mp4: silence unused variable warning
The variable was not used when zlib is not available. Silence it when
the code is disabled.
- - - - -
5a42e03e by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
vcd: cdrom: add missing allocation check
- - - - -
2fc3d155 by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
http: add missing allocation check
- - - - -
228a8b8d by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
codec: dmo: fix allocation check
- - - - -
4d45af8d by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
demux/mp4: heif: add missing allocation check
- - - - -
effe39be by Alexandre Janniaux at 2023-09-21T08:50:00+00:00
demux/mp4: mp4: add missing allocation check
Report ENOMEM through the control return value.
- - - - -
13 changed files:
- include/vlc_input.h
- modules/access/http.c
- modules/access/vcd/cdrom.c
- modules/codec/dmo/dmo.c
- modules/demux/mp4/heif.c
- modules/demux/mp4/libmp4.c
- modules/demux/mp4/mp4.c
- modules/demux/ogg.c
- modules/mux/mp4/libmp4mux.c
- modules/mux/mp4/libmp4mux.h
- modules/mux/mp4/mp4.c
- modules/stream_out/rtp.c
- modules/video_chroma/copy.c
Changes:
=====================================
include/vlc_input.h
=====================================
@@ -73,11 +73,19 @@ static inline void vlc_seekpoint_Delete( seekpoint_t *point )
static inline seekpoint_t *vlc_seekpoint_Duplicate( const seekpoint_t *src )
{
seekpoint_t *point = vlc_seekpoint_New();
- if( likely(point) )
+ if (unlikely(point == NULL))
+ return NULL;
+
+ if (src->psz_name)
{
- if( src->psz_name ) point->psz_name = strdup( src->psz_name );
- point->i_time_offset = src->i_time_offset;
+ point->psz_name = strdup(src->psz_name);
+ if (point->psz_name == NULL)
+ {
+ vlc_seekpoint_Delete(point);
+ return NULL;
+ }
}
+ point->i_time_offset = src->i_time_offset;
return point;
}
=====================================
modules/access/http.c
=====================================
@@ -475,6 +475,9 @@ static int ReadICYMeta( stream_t *p_access )
/* msg_Dbg( p_access, "ICY meta size=%u", i_size); */
psz_meta = malloc( i_size + 1 );
+ if (psz_meta == NULL)
+ return VLC_ENOMEM;
+
for( i_read = 0; i_read < i_size; )
{
int i_tmp;
=====================================
modules/access/vcd/cdrom.c
=====================================
@@ -864,6 +864,11 @@ static int OpenVCDImage( vlc_object_t * p_this, const char *psz_dev,
{
psz_vcdfile = malloc( strlen(filename) +
(p_pos - psz_cuefile + 1) + 1 );
+ if (psz_vcdfile == NULL)
+ {
+ i_ret = VLC_ENOMEM;
+ goto error;
+ }
strncpy( psz_vcdfile, psz_cuefile, (p_pos - psz_cuefile + 1) );
strcpy( psz_vcdfile + (p_pos - psz_cuefile + 1), filename );
} else psz_vcdfile = strdup( filename );
@@ -1685,4 +1690,3 @@ int ioctl_GetCdText( vlc_object_t *p_object, const vcddev_t *p_vcddev,
free( p_text );
return 0;
}
-
=====================================
modules/codec/dmo/dmo.c
=====================================
@@ -302,6 +302,8 @@ static int DecOpen( decoder_t *p_dec )
VIDEOINFOHEADER *p_vih = NULL;
WAVEFORMATEX *p_wf = NULL;
+ int i_ret = VLC_EGENERIC;
+
/* Initialize OLE/COM */
if( FAILED(CoInitializeEx( NULL, COINIT_MULTITHREADED )) )
vlc_assert_unreachable();
@@ -323,6 +325,8 @@ static int DecOpen( decoder_t *p_dec )
uint16_t i_tag;
int i_size = sizeof(WAVEFORMATEX) + p_dec->fmt_in->i_extra;
p_wf = malloc( i_size );
+ if (p_wf == NULL)
+ goto allocation_failure;
memset( p_wf, 0, sizeof(WAVEFORMATEX) );
if( p_dec->fmt_in->i_extra )
@@ -356,6 +360,8 @@ static int DecOpen( decoder_t *p_dec )
int i_size = sizeof(VIDEOINFOHEADER) + p_dec->fmt_in->i_extra;
p_vih = malloc( i_size );
+ if (p_vih == NULL)
+ goto allocation_failure;
memset( p_vih, 0, sizeof(VIDEOINFOHEADER) );
if( p_dec->fmt_in->i_extra )
@@ -571,8 +577,10 @@ static int DecOpen( decoder_t *p_dec )
return VLC_SUCCESS;
- error:
+allocation_failure:
+ i_ret = VLC_ENOMEM;
+error:
if( p_dmo ) IMediaObject_Release( p_dmo );
if( hmsdmo_dll ) FreeLibrary( hmsdmo_dll );
@@ -586,7 +594,7 @@ static int DecOpen( decoder_t *p_dec )
p_sys->b_ready = true;
vlc_cond_signal( &p_sys->wait_output );
vlc_mutex_unlock( &p_sys->lock );
- return VLC_EGENERIC;
+ return i_ret;
}
/*****************************************************************************
@@ -1179,6 +1187,11 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
}
p_data = malloc( i_data );
+ if (p_data == NULL)
+ {
+ DMOFreeMediaType( &dmo_type );
+ return VLC_ENOMEM;
+ }
i_err = p_privdata->vt->GetPrivateData( p_privdata, p_data, &i_data );
/* Update the media type with the private data */
=====================================
modules/demux/mp4/heif.c
=====================================
@@ -141,8 +141,18 @@ static int ControlHEIF( demux_t *p_demux, int i_query, va_list args )
return VLC_EGENERIC;
*pi_int = 1;
- *ppp_title = malloc( sizeof( input_title_t*) );
- (*ppp_title)[0] = vlc_input_title_Duplicate( p_sys->p_title );
+ input_title_t **titles = malloc(sizeof(*titles));
+ if (titles == NULL)
+ return VLC_ENOMEM;
+
+ titles[0] = vlc_input_title_Duplicate(p_sys->p_title);
+ if (titles[0] == NULL)
+ {
+ free(titles);
+ return VLC_ENOMEM;
+ }
+
+ *ppp_title = titles;
*pi_title_offset = 0;
*pi_seekpoint_offset = 0;
return VLC_SUCCESS;
=====================================
modules/demux/mp4/libmp4.c
=====================================
@@ -3497,6 +3497,7 @@ static int MP4_ReadBox_cmvd( stream_t *p_stream, MP4_Box_t *p_box )
static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box )
{
#ifndef HAVE_ZLIB
+ (void)p_box;
msg_Dbg( p_stream, "read box: \"cmov\" zlib unsupported" );
return 0;
#else
=====================================
modules/demux/mp4/mp4.c
=====================================
@@ -2341,8 +2341,17 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
return VLC_EGENERIC;
*pi_int = 1;
- *ppp_title = malloc( sizeof( input_title_t*) );
- (*ppp_title)[0] = vlc_input_title_Duplicate( p_sys->p_title );
+ input_title_t **titles = malloc(sizeof(*titles));
+ if (titles == NULL)
+ return VLC_ENOMEM;
+
+ titles[0] = vlc_input_title_Duplicate(p_sys->p_title);
+ if (titles[0] == NULL)
+ {
+ free(titles);
+ return VLC_ENOMEM;
+ }
+ *ppp_title = titles;
*pi_title_offset = 0;
*pi_seekpoint_offset = 0;
return VLC_SUCCESS;
@@ -2457,7 +2466,10 @@ static void LoadChapterGpac( demux_t *p_demux, MP4_Box_t *p_chpl )
return;
p_sys->p_title = vlc_input_title_New();
- for( int i = 0; i < BOXDATA(p_chpl)->i_chapter && p_sys->p_title; i++ )
+ if (p_sys->p_title == NULL)
+ return;
+
+ for( int i = 0; i < BOXDATA(p_chpl)->i_chapter; i++ )
{
seekpoint_t *s = vlc_seekpoint_New();
if( s == NULL) continue;
=====================================
modules/demux/ogg.c
=====================================
@@ -855,22 +855,40 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
int *pi_title_offset = va_arg( args, int* );
int *pi_seekpoint_offset = va_arg( args, int* );
- if( p_sys->i_seekpoints > 0 )
+ if( p_sys->i_seekpoints == 0 )
+ return VLC_EGENERIC;
+
+ *pi_int = 1;
+ input_title_t **titles = malloc(sizeof(*titles));
+ if (titles == NULL)
+ return VLC_ENOMEM;
+
+ titles[0] = vlc_input_title_New();
+ if (titles[0] == NULL)
+ {
+ free(titles);
+ return VLC_ENOMEM;
+ }
+
+ for( int i = 0; i < p_sys->i_seekpoints; i++ )
{
- *pi_int = 1;
- *ppp_title = malloc( sizeof( input_title_t* ) );
- input_title_t *p_title = (*ppp_title)[0] = vlc_input_title_New();
- for( int i = 0; i < p_sys->i_seekpoints; i++ )
+ seekpoint_t *p_seekpoint_copy = vlc_seekpoint_Duplicate( p_sys->pp_seekpoints[i] );
+ if (unlikely(p_seekpoint_copy == NULL))
{
- seekpoint_t *p_seekpoint_copy = vlc_seekpoint_Duplicate( p_sys->pp_seekpoints[i] );
- if ( likely( p_seekpoint_copy ) )
- TAB_APPEND( p_title->i_seekpoint, p_title->seekpoint, p_seekpoint_copy );
+ for (int j = 0; j < i; ++j)
+ {
+ vlc_seekpoint_Delete(titles[0]->seekpoint[i]);
+ }
+ vlc_input_title_Delete(titles[0]);
+ free(titles);
+ return VLC_ENOMEM;
}
- *pi_title_offset = 0;
- *pi_seekpoint_offset = 0;
- return VLC_SUCCESS;
+ TAB_APPEND(titles[0]->i_seekpoint, titles[0]->seekpoint, p_seekpoint_copy);
}
- return VLC_EGENERIC;
+ *ppp_title = titles;
+ *pi_title_offset = 0;
+ *pi_seekpoint_offset = 0;
+ return VLC_SUCCESS;
}
case DEMUX_SET_TITLE:
{
=====================================
modules/mux/mp4/libmp4mux.c
=====================================
@@ -134,7 +134,9 @@ static bool mp4mux_trackinfo_Init(mp4mux_trackinfo_t *p_stream, unsigned i_id,
static void mp4mux_trackinfo_Clear(mp4mux_trackinfo_t *p_stream)
{
es_format_Clean(&p_stream->fmt);
- mp4mux_track_SetSamplePriv(p_stream, NULL, 0);
+ int ret = mp4mux_track_SetSamplePriv(p_stream, NULL, 0);
+ assert(ret == VLC_SUCCESS);
+
free(p_stream->samples);
free(p_stream->p_edits);
}
@@ -295,8 +297,8 @@ enum mp4mux_interlacing mp4mux_track_GetInterlacing(const mp4mux_trackinfo_t *t)
return t->e_interlace;
}
-void mp4mux_track_SetSamplePriv(mp4mux_trackinfo_t *t,
- const uint8_t *p_data, size_t i_data)
+int mp4mux_track_SetSamplePriv(mp4mux_trackinfo_t *t,
+ const uint8_t *p_data, size_t i_data)
{
if(t->sample_priv.p_data)
{
@@ -308,12 +310,12 @@ void mp4mux_track_SetSamplePriv(mp4mux_trackinfo_t *t,
if(p_data && i_data)
{
t->sample_priv.p_data = malloc(i_data);
- if(i_data)
- {
- memcpy(t->sample_priv.p_data, p_data, i_data);
- t->sample_priv.i_data = i_data;
- }
+ if (t->sample_priv.p_data == NULL)
+ return VLC_ENOMEM;
+ memcpy(t->sample_priv.p_data, p_data, i_data);
+ t->sample_priv.i_data = i_data;
}
+ return VLC_SUCCESS;
}
bool mp4mux_track_HasSamplePriv(const mp4mux_trackinfo_t *t)
=====================================
modules/mux/mp4/libmp4mux.h
=====================================
@@ -59,7 +59,7 @@ enum mp4mux_interlacing
};
void mp4mux_track_SetInterlacing(mp4mux_trackinfo_t *, enum mp4mux_interlacing);
enum mp4mux_interlacing mp4mux_track_GetInterlacing(const mp4mux_trackinfo_t *);
-void mp4mux_track_SetSamplePriv(mp4mux_trackinfo_t *, const uint8_t *, size_t);
+int mp4mux_track_SetSamplePriv(mp4mux_trackinfo_t *, const uint8_t *, size_t);
bool mp4mux_track_HasSamplePriv(const mp4mux_trackinfo_t *);
vlc_tick_t mp4mux_track_GetDefaultSampleDuration(const mp4mux_trackinfo_t *);
uint32_t mp4mux_track_GetDefaultSampleSize(const mp4mux_trackinfo_t *);
@@ -103,4 +103,3 @@ void box_fix (bo_t *box, uint32_t);
void box_gather (bo_t *box, bo_t *box2);
bool mp4mux_CanMux(vlc_object_t *, const es_format_t *, vlc_fourcc_t, bool);
-
=====================================
modules/mux/mp4/mp4.c
=====================================
@@ -604,21 +604,33 @@ static bool CreateCurrentEdit(mp4_stream_t *p_stream, vlc_tick_t i_mux_start_dts
return mp4mux_track_AddEdit(p_stream->tinfo, &newedit);
}
-static block_t * BlockDequeue(sout_input_t *p_input, mp4_stream_t *p_stream)
+static int BlockDequeue(sout_input_t *p_input, mp4_stream_t *p_stream, block_t **out)
{
+ assert(out);
+
block_t *p_block = block_FifoGet(p_input->p_fifo);
if(unlikely(!p_block))
- return NULL;
+ {
+ *out = NULL;
+ return VLC_SUCCESS;
+ }
/* Create on the fly extradata as packetizer is not in the loop */
if(p_stream->extrabuilder && !mp4mux_track_HasSamplePriv(p_stream->tinfo))
{
- mux_extradata_builder_Feed(p_stream->extrabuilder,
- p_block->p_buffer, p_block->i_buffer);
- const uint8_t *p_extra;
- size_t i_extra = mux_extradata_builder_Get(p_stream->extrabuilder, &p_extra);
- if(i_extra)
- mp4mux_track_SetSamplePriv(p_stream->tinfo, p_extra, i_extra);
+ mux_extradata_builder_Feed(p_stream->extrabuilder,
+ p_block->p_buffer, p_block->i_buffer);
+ const uint8_t *p_extra;
+ size_t i_extra = mux_extradata_builder_Get(p_stream->extrabuilder, &p_extra);
+ if (i_extra)
+ {
+ int ret = mp4mux_track_SetSamplePriv(p_stream->tinfo, p_extra, i_extra);
+ if (ret != VLC_SUCCESS)
+ {
+ block_Release(p_block);
+ return ret;
+ }
+ }
}
switch(mp4mux_track_GetFmt(p_stream->tinfo)->i_codec)
@@ -637,7 +649,8 @@ static block_t * BlockDequeue(sout_input_t *p_input, mp4_stream_t *p_stream)
break;
}
- return p_block;
+ *out = p_block;
+ return VLC_SUCCESS;
}
static inline vlc_tick_t dts_fb_pts( const block_t *p_data )
@@ -1455,7 +1468,12 @@ static int MuxFrag(sout_mux_t *p_mux)
sout_input_t *p_input = p_mux->pp_inputs[i_stream];
mp4_stream_t *p_stream = (mp4_stream_t*) p_input->p_sys;
- block_t *p_currentblock = BlockDequeue(p_input, p_stream);
+
+ block_t *p_currentblock;
+ int ret = BlockDequeue(p_input, p_stream, &p_currentblock);
+ if (ret != VLC_SUCCESS)
+ return ret;
+
if( !p_currentblock )
return VLC_SUCCESS;
=====================================
modules/stream_out/rtp.c
=====================================
@@ -1312,6 +1312,11 @@ static int HttpCallback( httpd_file_sys_t *p_args,
{
*pi_data = strlen( p_sys->psz_sdp );
*pp_data = malloc( *pi_data );
+ if (*pp_data == NULL)
+ {
+ vlc_mutex_unlock(&p_sys->lock_sdp);
+ return VLC_ENOMEM;
+ }
memcpy( *pp_data, p_sys->psz_sdp, *pi_data );
}
else
=====================================
modules/video_chroma/copy.c
=====================================
@@ -1089,17 +1089,27 @@ static picture_t *pic_new_unaligned(const video_format_t *fmt)
{
/* Allocate a no-aligned picture in order to ease buffer overflow detection
* from the source picture */
+ unsigned i = 0;
const vlc_chroma_description_t *dsc = vlc_fourcc_GetChromaDescription(fmt->i_chroma);
assert(dsc);
picture_resource_t rsc = { .pf_destroy = pic_rsc_destroy };
- for (unsigned i = 0; i < dsc->plane_count; i++)
+ for (; i < dsc->plane_count; i++)
{
rsc.p[i].i_lines = ((fmt->i_visible_height + (dsc->p[i].h.den - 1)) / dsc->p[i].h.den) * dsc->p[i].h.num;
rsc.p[i].i_pitch = ((fmt->i_visible_width + (dsc->p[i].w.den - 1)) / dsc->p[i].w.den) * dsc->p[i].w.num * dsc->pixel_size;
rsc.p[i].p_pixels = malloc(rsc.p[i].i_lines * rsc.p[i].i_pitch);
- assert(rsc.p[i].p_pixels);
+ if (rsc.p[i].p_pixels == NULL)
+ goto cleanup;
}
- return picture_NewFromResource(fmt, &rsc);
+ picture_t *pic = picture_NewFromResource(fmt, &rsc);
+ if (pic == NULL)
+ goto cleanup;
+ return pic;
+
+cleanup:
+ while (i != 0)
+ free(rsc.p[--i].p_pixels);
+ return NULL;
}
int main(void)
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f27aa54bf22db48b89eba982e2452d202e84ac71...effe39be81f79173b593fe0f3934c7a52f457529
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f27aa54bf22db48b89eba982e2452d202e84ac71...effe39be81f79173b593fe0f3934c7a52f457529
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