diff --git a/format/mp4/mp4io/atoms.go b/format/mp4/mp4io/atoms.go index 901a7139..fa21d44e 100644 --- a/format/mp4/mp4io/atoms.go +++ b/format/mp4/mp4io/atoms.go @@ -1,7 +1,7 @@ package mp4io import ( - "log" + "errors" "time" "github.com/deepch/vdk/utils/bits/pio" @@ -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: @@ -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) } } @@ -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 @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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: @@ -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) } } @@ -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) } } @@ -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: @@ -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) } } @@ -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) @@ -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 { { diff --git a/format/mp4m/mp4io/atoms.go b/format/mp4m/mp4io/atoms.go index 3f8c584d..fa21d44e 100644 --- a/format/mp4m/mp4io/atoms.go +++ b/format/mp4m/mp4io/atoms.go @@ -1,6 +1,7 @@ package mp4io import ( + "errors" "time" "github.com/deepch/vdk/utils/bits/pio" @@ -24,17 +25,18 @@ func (self AVC1Desc) Tag() Tag { return AVC1 } -//0x31766568 +// 0x31766568 const HEV1 = Tag(0x68766331) func (self HV1Desc) Tag() Tag { return HEV1 } -//const HVC1 = Tag(0x68766331) -//func (self HVC1Desc) Tag() Tag { -// return HVC1 -//} +// const HVC1 = Tag(0x68766331) +// +// func (self HVC1Desc) Tag() Tag { +// return HVC1 +// } const URL = Tag(0x75726c20) func (self DataReferUrl) Tag() Tag { @@ -304,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: @@ -313,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) } } @@ -601,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) } } @@ -940,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) } } @@ -1173,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) } } @@ -1255,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) } } @@ -1817,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) } } @@ -1982,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) } } @@ -2291,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) } } @@ -2411,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) } } @@ -2954,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: @@ -2963,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) } } @@ -3127,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) } } @@ -3197,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: @@ -3206,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) } }