Skip to content

fix: limit memory usage in reading invalid subs box#404

Merged
tobbee merged 1 commit intoEyevinn:masterfrom
fancybits:fix-subs-box
Jan 20, 2025
Merged

fix: limit memory usage in reading invalid subs box#404
tobbee merged 1 commit intoEyevinn:masterfrom
fancybits:fix-subs-box

Conversation

@eric
Copy link
Contributor

@eric eric commented Jan 19, 2025

Found this when fuzzing:

ROUTINE ======================== github.com/Eyevinn/mp4ff/mp4.DecodeSubsSR in /Users/eric/src/mp4ff/mp4/subs.go
  255.17GB   255.17GB (flat, cum)   100% of Total
         .          .     69:func DecodeSubsSR(hdr BoxHeader, startPos uint64, sr bits.SliceReader) (Box, error) {
         .          .     70:	versionAndFlags := sr.ReadUint32()
         .          .     71:	version := byte(versionAndFlags >> 24)
         .          .     72:
         .          .     73:	b := SubsBox{
         .          .     74:		Version: version,
         .          .     75:		Flags:   versionAndFlags & flagsMask,
         .          .     76:	}
         .          .     77:	entryCount := sr.ReadUint32()
         .          .     78:	for i := uint32(0); i < entryCount; i++ {
         .          .     79:		e := SubsEntry{}
         .          .     80:		e.SampleDelta = sr.ReadUint32()
         .          .     81:		subsampleCount := sr.ReadUint16()
         .          .     82:		for j := uint16(0); j < subsampleCount; j++ {
         .          .     83:			ss := SubsSample{}
         .          .     84:			if version == 1 {
         .          .     85:				ss.SubsampleSize = sr.ReadUint32()
         .          .     86:			} else {
         .          .     87:				ss.SubsampleSize = uint32(sr.ReadUint16())
         .          .     88:			}
         .          .     89:			ss.SubsamplePriority = sr.ReadUint8()
         .          .     90:			ss.Discardable = sr.ReadUint8()
         .          .     91:			ss.CodecSpecificParameters = sr.ReadUint32()
    1.21MB     1.21MB     92:			e.SubSamples = append(e.SubSamples, ss)
         .          .     93:		}
  255.17GB   255.17GB     94:		b.Entries = append(b.Entries, e)
         .          .     95:	}
         .          .     96:	return &b, sr.AccError()
         .          .     97:}
         .          .     98:
         .          .     99:// Type - return box type

Copy link
Collaborator

@tobbee tobbee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@tobbee tobbee merged commit 5fb4e82 into Eyevinn:master Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants