diff --git a/format/id3/id3v2.go b/format/id3/id3v2.go index 10635479..2944ce7d 100644 --- a/format/id3/id3v2.go +++ b/format/id3/id3v2.go @@ -368,7 +368,7 @@ func decodeFrame(d *decode.D, version int) uint64 { d.FieldU5("unused0") d.FieldBool("compression") - // TODO: read encruption byte, skip decode of frame data? + // TODO: read encryption byte, skip decode of frame data? d.FieldBool("encryption") d.FieldBool("grouping_identity") @@ -399,7 +399,7 @@ func decodeFrame(d *decode.D, version int) uint64 { d.FieldU2("unused2") d.FieldBool("compression") - // TODO: read encruption byte, skip decode of frame data? + // TODO: read encryption byte, skip decode of frame data? d.FieldBool("encryption") unsyncFlag = d.FieldBool("unsync") dataLenFlag = d.FieldBool("data_length_indicator") @@ -577,11 +577,10 @@ func decodeFrames(d *decode.D, version int, size uint64) { size -= decodeFrame(d, version) }) } - }) if size > 0 { - d.FieldValidateZeroPadding("padding", int(size)*8) + d.FieldZeroPadding("padding", int(size)*8) } } diff --git a/pkg/decode/decode_readers.go b/pkg/decode/decode_readers.go index 0b5aca3d..dc34f498 100644 --- a/pkg/decode/decode_readers.go +++ b/pkg/decode/decode_readers.go @@ -175,7 +175,7 @@ func (d *D) FieldOptionalZeroBytes(name string) int64 { }) } -func (d *D) FieldValidateZeroPadding(name string, nBits int) { +func (d *D) fieldZeroPadding(name string, nBits int, panicOnNonZero bool) { pos := d.Pos() var isZero bool d.FieldFn(name, func() *Value { @@ -184,13 +184,22 @@ func (d *D) FieldValidateZeroPadding(name string, nBits int) { if !isZero { s = "Incorrect" } + // TODO: proper warnings return &Value{Symbol: s, Description: "zero padding"} }) - if !isZero { + if panicOnNonZero && !isZero { panic(ValidateError{Reason: "expected zero padding", Pos: pos}) } } +func (d *D) FieldValidateZeroPadding(name string, nBits int) { + d.fieldZeroPadding(name, nBits, true) +} + +func (d *D) FieldZeroPadding(name string, nBits int) { + d.fieldZeroPadding(name, nBits, false) +} + // Bool reads one bit as a boolean func (d *D) TryBool() (bool, error) { n, err := d.TryU(1)