1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 13:22:58 +03:00

mp3: Be more relaxed with zero padding, just warn

This commit is contained in:
Mattias Wadman 2021-09-07 11:51:18 +02:00
parent d350971fa2
commit da386ea282
2 changed files with 14 additions and 6 deletions

View File

@ -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)
}
}

View File

@ -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)