diff options
| author | 2023-10-09 10:13:37 +0200 | |
|---|---|---|
| committer | 2023-10-09 10:13:37 +0200 | |
| commit | abd598e8f63f640497242c62e004b4a75601482e (patch) | |
| tree | ce51addf774dbce0ed3d6187d6436f88190ad10d /vendor/github.com/abema/go-mp4/marshaller.go | |
| parent | [chore]: Bump golang.org/x/net from 0.15.0 to 0.16.0 (#2260) (diff) | |
| download | gotosocial-abd598e8f63f640497242c62e004b4a75601482e.tar.xz | |
[chore]: Bump github.com/abema/go-mp4 from 1.0.0 to 1.1.1 (#2257)
Bumps [github.com/abema/go-mp4](https://github.com/abema/go-mp4) from 1.0.0 to 1.1.1.
- [Release notes](https://github.com/abema/go-mp4/releases)
- [Commits](https://github.com/abema/go-mp4/compare/v1.0.0...v1.1.1)
---
updated-dependencies:
- dependency-name: github.com/abema/go-mp4
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/abema/go-mp4/marshaller.go')
| -rw-r--r-- | vendor/github.com/abema/go-mp4/marshaller.go | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/vendor/github.com/abema/go-mp4/marshaller.go b/vendor/github.com/abema/go-mp4/marshaller.go index 18ff79a0c..ff6c64c32 100644 --- a/vendor/github.com/abema/go-mp4/marshaller.go +++ b/vendor/github.com/abema/go-mp4/marshaller.go @@ -17,6 +17,29 @@ const ( var ErrUnsupportedBoxVersion = errors.New("unsupported box version") +func readerHasSize(reader bitio.ReadSeeker, size uint64) bool { + pre, err := reader.Seek(0, io.SeekCurrent) + if err != nil { + return false + } + + end, err := reader.Seek(0, io.SeekEnd) + if err != nil { + return false + } + + if uint64(end-pre) < size { + return false + } + + _, err = reader.Seek(pre, io.SeekStart) + if err != nil { + return false + } + + return true +} + type marshaller struct { writer bitio.Writer wbits uint64 @@ -417,12 +440,13 @@ func (u *unmarshaller) unmarshalSlice(v reflect.Value, fi *fieldInstance) error } } - if length > math.MaxInt32 { - return fmt.Errorf("out of memory: requestedSize=%d", length) - } - - if fi.size != 0 && fi.size%8 == 0 && u.rbits%8 == 0 && elemType.Kind() == reflect.Uint8 && fi.size == 8 { + if u.rbits%8 == 0 && elemType.Kind() == reflect.Uint8 && fi.size == 8 { totalSize := length * uint64(fi.size) / 8 + + if !readerHasSize(u.reader, totalSize) { + return fmt.Errorf("not enough bits") + } + buf := bytes.NewBuffer(make([]byte, 0, totalSize)) if _, err := io.CopyN(buf, u.reader, int64(totalSize)); err != nil { return err @@ -431,7 +455,7 @@ func (u *unmarshaller) unmarshalSlice(v reflect.Value, fi *fieldInstance) error u.rbits += uint64(totalSize) * 8 } else { - slice = reflect.MakeSlice(v.Type(), 0, int(length)) + slice = reflect.MakeSlice(v.Type(), 0, 0) for i := 0; ; i++ { if fi.length != LengthUnlimited && uint(i) >= fi.length { break |
