From da386ea282bd9ed28f62e4d2a3e1172a9bbf5b2b Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Tue, 7 Sep 2021 11:51:18 +0200 Subject: [PATCH] mp3: Be more relaxed with zero padding, just warn --- format/id3/id3v2.go | 7 +++---- pkg/decode/decode_readers.go | 13 +++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) 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)