Skip to content

Commit

Permalink
flac_frame: Make utf8Uint reader more correct and robust
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Sep 29, 2021
1 parent d365ab7 commit 723542a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions format/flac/flac_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@ func utf8Uint(d *decode.D) uint64 {
n := d.U8()
// leading ones, bit negate and count zeroes
c := bits.LeadingZeros8(^uint8(n))
// 0b0xxxxxxx 1 byte
// 0b110xxxxx 2 byte
// 0b1110xxxx 3 byte
// 0b11110xxx 4 byte
switch c {
case 0:
// nop
case 1:
// TODO: error
d.Invalid("invalid UTF8Uint")
default:
case 2, 3, 4:
n = n & ((1 << (8 - c - 1)) - 1)
for i := 1; i < c; i++ {
n = n<<6 | d.U8()&0x3f
}
default:
d.Invalid("invalid UTF8Uint")
}
return n
}
Expand Down

0 comments on commit 723542a

Please sign in to comment.