Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
deepch committed Dec 18, 2024
1 parent 7bb8737 commit dc22c36
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 40 deletions.
96 changes: 61 additions & 35 deletions format/mp4/mp4io/atoms.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mp4io

import (
"log"
"errors"
"time"

"github.com/deepch/vdk/utils/bits/pio"
Expand Down Expand Up @@ -306,6 +306,10 @@ func (self *Movie) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("trak", n+offset, err)
return
}
if len(self.Tracks) > 100 {
err = errors.New("too many tracks")
return
}
self.Tracks = append(self.Tracks, atom)
}
default:
Expand All @@ -315,6 +319,10 @@ func (self *Movie) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -573,11 +581,6 @@ func (self *Track) Unmarshal(b []byte, offset int) (n int, err error) {
for n+8 < len(b) {
tag := Tag(pio.U32BE(b[n+4:]))
size := int(pio.U32BE(b[n:]))
if size > 5242880 {
log.Println("track size", size)
err = parseErr("_len_Entries", 5242880, err)
return
}
if len(b) < n+size {
err = parseErr("TagSizeInvalid", n+offset, err)
return
Expand Down Expand Up @@ -608,6 +611,10 @@ func (self *Track) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -947,6 +954,10 @@ func (self *Media) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -1180,6 +1191,10 @@ func (self *MediaInfo) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -1262,6 +1277,10 @@ func (self *DataInfo) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -1824,6 +1843,10 @@ func (self *SampleDesc) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -1989,6 +2012,10 @@ func (self *MP4ADesc) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -2298,6 +2325,10 @@ func (self *AVC1Desc) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -2418,6 +2449,10 @@ func (self *HV1Desc) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -2559,10 +2594,6 @@ func (self *TimeToSample) Unmarshal(b []byte, offset int) (n int, err error) {
var _len_Entries uint32
_len_Entries = pio.U32BE(b[n:])
n += 4
if _len_Entries > 5242880 {
err = parseErr("_len_Entries", 5242880, err)
return
}
self.Entries = make([]TimeToSampleEntry, _len_Entries)
if len(b) < n+LenTimeToSampleEntry*len(self.Entries) {
err = parseErr("TimeToSampleEntry", n+offset, err)
Expand Down Expand Up @@ -2647,10 +2678,6 @@ func (self *SampleToChunk) Unmarshal(b []byte, offset int) (n int, err error) {
var _len_Entries uint32
_len_Entries = pio.U32BE(b[n:])
n += 4
if _len_Entries > 5242880 {
err = parseErr("_len_Entries", 5242880, err)
return
}
self.Entries = make([]SampleToChunkEntry, _len_Entries)
if len(b) < n+LenSampleToChunkEntry*len(self.Entries) {
err = parseErr("SampleToChunkEntry", n+offset, err)
Expand Down Expand Up @@ -2738,10 +2765,6 @@ func (self *CompositionOffset) Unmarshal(b []byte, offset int) (n int, err error
var _len_Entries uint32
_len_Entries = pio.U32BE(b[n:])
n += 4
if _len_Entries > 5242880 {
err = parseErr("_len_Entries", 5242880, err)
return
}
self.Entries = make([]CompositionOffsetEntry, _len_Entries)
if len(b) < n+LenCompositionOffsetEntry*len(self.Entries) {
err = parseErr("CompositionOffsetEntry", n+offset, err)
Expand Down Expand Up @@ -2826,10 +2849,6 @@ func (self *SyncSample) Unmarshal(b []byte, offset int) (n int, err error) {
var _len_Entries uint32
_len_Entries = pio.U32BE(b[n:])
n += 4
if _len_Entries > 5242880 {
err = parseErr("_len_Entries", 5242880, err)
return
}
self.Entries = make([]uint32, _len_Entries)
if len(b) < n+4*len(self.Entries) {
err = parseErr("uint32", n+offset, err)
Expand Down Expand Up @@ -2897,10 +2916,6 @@ func (self *ChunkOffset) Unmarshal(b []byte, offset int) (n int, err error) {
var _len_Entries uint32
_len_Entries = pio.U32BE(b[n:])
n += 4
if _len_Entries > 5242880 {
err = parseErr("_len_Entries", 5242880, err)
return
}
self.Entries = make([]uint32, _len_Entries)
if len(b) < n+4*len(self.Entries) {
err = parseErr("uint32", n+offset, err)
Expand Down Expand Up @@ -2981,6 +2996,10 @@ func (self *MovieFrag) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("traf", n+offset, err)
return
}
if len(self.Tracks) > 100 {
err = errors.New("too many tracks")
return
}
self.Tracks = append(self.Tracks, atom)
}
default:
Expand All @@ -2990,6 +3009,10 @@ func (self *MovieFrag) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -3154,6 +3177,10 @@ func (self *TrackFrag) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -3224,6 +3251,10 @@ func (self *MovieExtend) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("trex", n+offset, err)
return
}
if len(self.Tracks) > 100 {
err = errors.New("too many tracks")
return
}
self.Tracks = append(self.Tracks, atom)
}
default:
Expand All @@ -3233,6 +3264,10 @@ func (self *MovieExtend) Unmarshal(b []byte, offset int) (n int, err error) {
err = parseErr("", n+offset, err)
return
}
if len(self.Unknowns) > 100 {
err = errors.New("too many unknowns")
return
}
self.Unknowns = append(self.Unknowns, atom)
}
}
Expand Down Expand Up @@ -3415,11 +3450,6 @@ func (self *SampleSize) Unmarshal(b []byte, offset int) (n int, err error) {
var _len_Entries uint32
_len_Entries = pio.U32BE(b[n:])
n += 4
if _len_Entries > 5242880 {
err = parseErr("_len_Entries", 5242880, err)
log.Println("_len_Entries", _len_Entries)
return
}
self.Entries = make([]uint32, _len_Entries)
if len(b) < n+4*len(self.Entries) {
err = parseErr("uint32", n+offset, err)
Expand Down Expand Up @@ -3552,10 +3582,6 @@ func (self *TrackFragRun) Unmarshal(b []byte, offset int) (n int, err error) {
var _len_Entries uint32
_len_Entries = pio.U32BE(b[n:])
n += 4
if _len_Entries > 5242880 {
err = parseErr("_len_Entries", 5242880, err)
return
}
self.Entries = make([]TrackFragRunEntry, _len_Entries)
if self.Flags&TRUN_DATA_OFFSET != 0 {
{
Expand Down
Loading

0 comments on commit dc22c36

Please sign in to comment.