History

avformat/matroskaenc: Reset cur_master_element when discarding master

Before this patch the muxer writes an invalid file (namely one in which the Projection master is a child of the Colour element) if the following conditions are met: a) The stream contains AVMasteringDisplayMetadata without primaries and luminance (i.e. useless AVMasteringDisplayMetadata). b) The stream contains AV_PKT_DATA_SPHERICAL side data. c) All the colour elements of the stream are equal to default (i.e. unknown). Fortunately these conditions are very unlikely to be met.

Andreas Rheinhardt committed 4 years ago

Commit 49a63c61 parent 9ff0fbb1 file · +10 −0Browse files

Unified · Split

libavformat/matroskaenc.c+10−0
@@ -444,15 +444,25 @@ static void ebml_writer_close_master(EbmlWriter *writer) · 443 unmodified lines
444444 av_assert2(writer->current_master_element < writer->nb_elements);
445445 elem = &writer->elements[writer->current_master_element];
446446 av_assert2(elem->type == EBML_MASTER);
447+ av_assert2(elem->priv.master.nb_elements < 0); /* means unset */
447448 elem->priv.master.nb_elements = writer->nb_elements - writer->current_master_element - 1;
449+ av_assert2(elem->priv.master.containing_master < 0 ||
450+ elem->priv.master.containing_master < writer->current_master_element);
448451 writer->current_master_element = elem->priv.master.containing_master;
449452 }
450453
451454 static void ebml_writer_close_or_discard_master(EbmlWriter *writer)
452455 {
453456 av_assert2(writer->nb_elements > 0);
457+ av_assert2(0 <= writer->current_master_element);
458+ av_assert2(writer->current_master_element < writer->nb_elements);
454459 if (writer->current_master_element == writer->nb_elements - 1) {
460+ const EbmlElement *const elem = &writer->elements[writer->nb_elements - 1];
455461 /* The master element has no children. Discard it. */
462+ av_assert2(elem->type == EBML_MASTER);
463+ av_assert2(elem->priv.master.containing_master < 0 ||
464+ elem->priv.master.containing_master < writer->current_master_element);
465+ writer->current_master_element = elem->priv.master.containing_master;
456466 writer->nb_elements--;
457467 return;
458468 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t