Skip to content

Commit

Permalink
fix: zero ignoring
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyoucao577 committed Dec 2, 2023
1 parent e3aabdd commit 72fdd0a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions container/mp4/box/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

// ParseBox tries to parse a box from a mount of data.
// return ErrUnknownBoxType if doesn't know, otherwise fatal error.
// return ErrUnknownBoxType if doesn't know, ErrInsufficientSize if no enough data,
// otherwise fatal error.
func ParseBox(r io.Reader, pb ParentBox, bytesAvailable uint64) (uint64, error) {
boxHeader := Header{}
if err := boxHeader.Parse(r, bytesAvailable); err != nil {
Expand All @@ -19,8 +20,10 @@ func ParseBox(r io.Reader, pb ParentBox, bytesAvailable uint64) (uint64, error)
bytesToIgnore := bytesAvailable - boxHeader.HeaderSize()
glog.Warningf("%v when parse header, ignore %s size %d", err, boxHeader.Type, bytesToIgnore)

if err := util.ReadOrError(r, make([]byte, bytesToIgnore)); err != nil {
return bytesAvailable, err
if bytesToIgnore > 0 {
if err := util.ReadOrError(r, make([]byte, bytesToIgnore)); err != nil {
return bytesAvailable, err
}
}
return bytesAvailable, err
}
Expand All @@ -38,8 +41,10 @@ func ParseBox(r io.Reader, pb ParentBox, bytesAvailable uint64) (uint64, error)
}
glog.Warningf("ignore %v when create sub box, type %s payload size %d (available %d)", err, boxHeader.Type, boxHeader.PayloadSize(), bytesAvailable)

if err := util.ReadOrError(r, make([]byte, bytesToIgnore)); err != nil {
return boxHeader.HeaderSize() + bytesToIgnore, err
if bytesToIgnore > 0 {
if err := util.ReadOrError(r, make([]byte, bytesToIgnore)); err != nil {
return boxHeader.HeaderSize() + bytesToIgnore, err
}
}
return boxHeader.HeaderSize() + bytesToIgnore, err
}
Expand Down

0 comments on commit 72fdd0a

Please sign in to comment.