Skip to content

Commit d394a24

Browse files
committed
Bugfix: Cluster test could have read past the end of the input buffer.
Move the cluster test inside the space-to-read check with the other tests.
1 parent 9de8fe4 commit d394a24

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/format_ebml.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,11 @@ static int ebml_wrote(ebml_t *ebml, int len)
588588

589589
/* Recognize tags of interest */
590590
if (tag_length > 4) {
591-
if (!memcmp(ebml->input_buffer + cursor, segment_id, 4)) {
591+
if (!memcmp(ebml->input_buffer + cursor, cluster_id, 4)) {
592+
/* Found a Cluster */
593+
ebml->parse_state = EBML_STATE_START_CLUSTER;
594+
break;
595+
} else if (!memcmp(ebml->input_buffer + cursor, segment_id, 4)) {
592596
/* Parse all Segment children */
593597
payload_length = 0;
594598

@@ -678,16 +682,11 @@ static int ebml_wrote(ebml_t *ebml, int len)
678682
}
679683
}
680684

681-
/* Take appropriate next action */
682-
if (!memcmp(ebml->input_buffer + cursor, cluster_id, 4)) {
683-
/* Found a cluster */
684-
ebml->parse_state = EBML_STATE_START_CLUSTER;
685-
686-
} else if (processing) {
685+
/* Copy any data we don't need to probe any more */
686+
if (processing) {
687687
/* Non-cluster tag, copy it & children into buffer */
688688
ebml->copy_len = tag_length + payload_length;
689689
ebml->parse_state = copy_state;
690-
691690
}
692691

693692
} else if (tag_length == 0) {

0 commit comments

Comments
 (0)