From 6216b2ed1fcd0b06a9e0b3ae74e5373a8cccd114 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Tue, 15 Sep 2026 00:06:58 +0200 Subject: track: bound malformed sample tables --- iter.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'iter.go') diff --git a/iter.go b/iter.go index 4b465d2..f9b47f4 100644 --- a/iter.go +++ b/iter.go @@ -32,6 +32,19 @@ func NewStszIter(data []byte) StszIter { // Count returns the total number of samples. func (it *StszIter) Count() uint32 { return it.count } +// ConstantSize reports whether the box encodes one size for every sample rather +// than a per-sample size table. +func (it *StszIter) ConstantSize() bool { return it.sampleSize != 0 } + +// SizeTableLen returns the number of per-sample size entries the box stores. It +// is zero for the constant-size form. +func (it *StszIter) SizeTableLen() int { + if it.sampleSize != 0 || len(it.buf) < 8 { + return 0 + } + return (len(it.buf) - 8) / 4 +} + // Next returns the next sample size. Returns (0, false) when done. func (it *StszIter) Next() (uint32, bool) { if it.index >= it.count { -- cgit v1.3.1