Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,13 @@ protected void startMasterElement(int id, long contentPosition, long contentSize
throw ParserException.createForMalformedContainer(
"Multiple Segment elements not supported", /* cause= */ null);
}

// If we have to reparse due to an IO exception we also have to clear the seek head data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious to me how you know that you've encountered an I/O exception if you land here

Is this the clearing logic I suggested maybe belongs in MatroskaExtractor.seek() in #2268 (comment)?

visitedSeekHeads.clear();
pendingSeekHeads.clear();
seekPositionAfterSeekingForHead = C.INDEX_UNSET;
seekForSeekContent = false;

segmentContentPosition = contentPosition;
segmentContentSize = contentSize;
break;
Expand Down Expand Up @@ -846,7 +853,10 @@ protected void endMasterElement(int id) throws ParserException {
} else if (seekEntryId == ID_SEEK_HEAD) {
// We have a set here to prevent inf recursion, only if this seek head is non
// visited we add it. VLC limits this to 10, but this should work equally as well.
if (visitedSeekHeads.add(seekEntryPosition)) {
//
// Note that we also need to check that we do not jump before or to the segment we are on
// as we do not want to clear our visitedSeekHeads
if (visitedSeekHeads.add(seekEntryPosition) && seekEntryPosition > segmentContentPosition) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seekEntryPosition > segmentContentPosition is needed to not seek above the segment to avoid clearing this visistedlist, however should this also be added to cues, or do we trust cues to be valid?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC it's not valid for the SeekPosition of SeekHead element inside segment A to point outside segment A into segment B?

In that case, it seems reasonable to trust that both the SeekHead and Cues elements are valid - with undefined behaviour (but probably an obscure parsing error) if they are not.

pendingSeekHeads.add(seekEntryPosition);
}
} else if (seekEntryId == ID_CUES) {
Expand Down