Skip to content

Commit

Permalink
Fix integer overflow during unfolding of the rice residual
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkKremer authored and mewmew committed Oct 24, 2023
1 parent 0b08a2f commit c51ad5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions frame/subframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ func (subframe *Subframe) decodeRiceResidual(br *bits.Reader, k uint) error {
if err != nil {
return unexpected(err)
}
residual := int32(high<<k | low)
folded := uint32(high<<k | low)

// ZigZag decode.
residual = bits.ZigZag(residual)
residual := bits.ZigZag(folded)
subframe.Samples = append(subframe.Samples, residual)

return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/bits/zigzag.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ package bits
// 6 => 3
//
// ref: https://developers.google.com/protocol-buffers/docs/encoding
func ZigZag(x int32) int32 {
return x>>1 ^ -(x & 1)
func ZigZag(x uint32) int32 {
return int32(x>>1) ^ -int32(x&1)
}

0 comments on commit c51ad5c

Please sign in to comment.