Fix #17921: NPE in track_block_get_next() (#17922)

This commit is contained in:
Michael Steenbeek authored and GitHub committed 2022-08-28 23:46:50 +02:00
1 parent a2f3ab84cc
commit 6c54bacd41
1 file changed
+10 -1
+10 -1
View File
@@ -557,7 +557,16 @@ bool track_block_get_next(CoordsXYE* input, CoordsXYE* output, int32_t* z, int32
if (trackBlock == nullptr)
return false;
trackBlock += inputElement->GetSequenceIndex();
// The sequence index may be higher than the amount of sequences actually present.
// We don’t know the amount of sequences present in the block upfront, but there is an end marker consisting of all 255s.
const auto sequenceIndex = inputElement->GetSequenceIndex();
for (auto i = 0; i < sequenceIndex; i++)
{
trackBlock++;
if (trackBlock == nullptr || trackBlock->index == 255)
return false;
}
const auto& trackCoordinate = ted.Coordinates;