amr: fix off-by-one in osmo_amr_bwe_to_oa()

The for loop in osmo_amr_bwe_to_oa, that converts the body part of the
AMR payload runs one byte too far. This may cause that some of the
padding bits in the end are not set to zero. The loop is designed to
convert n-1 bytes and the nth byte is done separately at the end.

Change-Id: I91e755b83aaac722079879c026d913cc446812d1
This commit is contained in:
Philipp Maier 2020-05-25 15:39:35 +02:00
parent 51591bbc3f
commit b61eaaccc3
3 changed files with 10 additions and 10 deletions

View File

@ -198,7 +198,7 @@ int osmo_amr_bwe_to_oa(uint8_t *payload, unsigned int payload_len,
return -1;
oa_payload_len = 2 + osmo_amr_bytes(oa_hdr->ft);
for (i = 0; i < oa_payload_len - 2; i++) {
for (i = 0; i < oa_payload_len - 3; i++) {
buf[i + 2] = payload[i + 1] << 2;
buf[i + 2] |= payload[i + 2] >> 6;
}

View File

@ -46,7 +46,7 @@ char *oa_amr_samples[] = {
"100c1fb967f7f1fdf547bf2e61c060",
"0004f89d67f1160935bde1996840",
"0004633cc7f0630439ffe0000000",
"0004eb81fc0758973b9edc782552",
"0004eb81fc0758973b9edc782550",
"a078ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00fc", /* sample with invalid FT */
"END",
};

View File

@ -143,10 +143,10 @@ Sample No.: 19
rc: 14
Sample No.: 20
octet aligned: 0004eb81fc0758973b9edc782552
0000000000000100111010111000000111111100000001110101100010010111001110111001111011011100011110000010010101010010
bw-efficient: 007ae07f01d625cee7b71e095480
0000000001111010111000000111111100000001110101100010010111001110111001111011011100011110000010010101010010000000
octet aligned: 0004eb81fc0758973b9edc782550
0000000000000100111010111000000111111100000001110101100010010111001110111001111011011100011110000010010101010000
bw-efficient: 007ae07f01d625cee7b71e095400
0000000001111010111000000111111100000001110101100010010111001110111001111011011100011110000010010101010000000000
rc: 14
Sample No.: 21
@ -162,15 +162,15 @@ Testing conversion from bw-efficient to octet-aligned:
Sample No.: 0
bw-efficient: f4495c7cda8f80
11110100010010010101110001111100110110101000111110000000
octet aligned: f0442571f36a3e
11110000010001000010010101110001111100110110101000111110
octet aligned: f0442571f36a3c
11110000010001000010010101110001111100110110101000111100
rc: 7
Sample No.: 1
bw-efficient: f44aaa6c969780
11110100010010101010101001101100100101101001011110000000
octet aligned: f0442aa9b25a5e
11110000010001000010101010101001101100100101101001011110
octet aligned: f0442aa9b25a5c
11110000010001000010101010101001101100100101101001011100
rc: 7
Sample No.: 2