avcodec/bsf/extract_extradata: don't use a NULL pointer to initialize an empty PutByteContext

Fixes UB in the form or adding a 0 offset to a NULL pointer, and substracting a
NULL pointer from another.

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer
2026-03-13 20:15:24 -03:00
parent 5ebd50415f
commit 2556db6173

View File

@@ -375,8 +375,9 @@ static int extract_extradata_lcevc(AVBSFContext *ctx, AVPacket *pkt,
for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
H2645NAL *nal = &s->h2645_pkt.nals[i];
if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) {
bytestream2_init_writer(&pb_extradata, NULL, 0);
// dummy pass to find sc, gc or ai
// dummy pass to find sc, gc or ai. A dummy pointer is used to prevent
// UB in PutByteContext. Nothing will be written.
bytestream2_init_writer(&pb_extradata, nal->data, 0);
if (!write_lcevc_nalu(ctx, &pb_extradata, nal, 0))
extradata_size += nal->raw_size + 3 +
ff_h2645_unit_requires_zero_byte(ctx->par_in->codec_id, nal->type, extradata_nb_nals++);