Skip to content

Commit

Permalink
fix: ensure there are no overflows in size calculation with trun
Browse files Browse the repository at this point in the history
  • Loading branch information
eric committed Jan 15, 2025
1 parent 5295d3a commit b8d62a8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mp4/trun.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ func (t *TrunBox) Size() uint64 {

// expectedSize - calculate size for a given sample count
func (t *TrunBox) expectedSize(sampleCount uint32) uint64 {
sz := boxHeaderSize + 8 // flags + entryCount
sz := uint64(boxHeaderSize + 8) // flags + entryCount
if t.HasDataOffset() {
sz += 4
}
if t.HasFirstSampleFlags() {
sz += 4
}
bytesPerSample := 0
var bytesPerSample uint64
if t.HasSampleDuration() {
bytesPerSample += 4
}
Expand All @@ -274,8 +274,8 @@ func (t *TrunBox) expectedSize(sampleCount uint32) uint64 {
if t.HasSampleCompositionTimeOffset() {
bytesPerSample += 4
}
sz += int(sampleCount) * bytesPerSample
return uint64(sz)
sz += uint64(sampleCount) * bytesPerSample
return sz
}

// Encode - write box to w
Expand Down

0 comments on commit b8d62a8

Please sign in to comment.