OSDN Git Service

A2DP: Fix integer sanitizer in SBC encoder
authorCheney Ni <cheneyni@google.com>
Sat, 11 Apr 2020 21:19:31 +0000 (05:19 +0800)
committerCheney Ni <cheneyni@google.com>
Fri, 17 Apr 2020 19:35:58 +0000 (03:35 +0800)
commit7f973d8726ed1bde875f66d773453ffb0c09bcb7
tree5015b84feb03922407d4743568b49277780641bf
parentd61cf5fe04063619afc6454034a7458d97bb0365
A2DP: Fix integer sanitizer in SBC encoder

There were three potential integer overflow within SBC software encoder:

* embdrv/sbc/encoder/srce/sbc_packing.c:144:38: runtime error: unsigned
  integer overflow: 4294967231 + 8192 cannot be represented in type
  'unsigned int'
* embdrv/sbc/encoder/srce/sbc_packing.c:147:9: runtime error: signed
  integer overflow: 37932 * 65535 cannot be represented in type 'int'
* embdrv/sbc/encoder/srce/sbc_packing.c:147:9: runtime error: signed
  integer overflow: 178177545 + 2146959360 cannot be represented in type
  'int'

They were caught by the integer sanitizer, and

1. (*ps32SbPtr >> 2) is either greater than 0xFF00,0000 or less than
   0x007F,FFFF, so just cast to a signed integer explicitly.
2. Positive integer between 0x8000,0000 ~ 0xFFFF,FFFF can't be
   represented in type 'int', but is still feasible in 32-bits.
3. s32OutLow is the lower byte of a 64 bits integer, but can't have the
   carry values which is only for the higher byte.

This change gives the compiler a signed 64-bits variable, and trusts it
to do better optimization at multiplication.

Bug: 153402404
Test: make sure there are no integer sanitization errors.
Change-Id: I5046a42f9927c1aa7c25da2828c4f921ba7a5021
Merged-In: I5046a42f9927c1aa7c25da2828c4f921ba7a5021
(cherry picked from commit a42db783434da238e4daade95ce2adb1bca0f138)
embdrv/sbc/encoder/srce/sbc_packing.c