diff options
author | Philipp Maier <pmaier@sysmocom.de> | 2020-05-25 15:39:35 +0200 |
---|---|---|
committer | Philipp Maier <pmaier@sysmocom.de> | 2020-05-25 17:05:04 +0200 |
commit | b61eaaccc37c8e7842a86bc06dcd0c0dd444e576 (patch) | |
tree | 194384463e602d62bb9143b6eae753ae767160e5 | |
parent | 51591bbc3f6264404d02f23fc7caaa4e1f9a090e (diff) |
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
-rw-r--r-- | src/amr.c | 2 | ||||
-rw-r--r-- | tests/amr/amr_test.c | 2 | ||||
-rw-r--r-- | tests/amr/amr_test.ok | 16 |
3 files changed, 10 insertions, 10 deletions
@@ -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; } diff --git a/tests/amr/amr_test.c b/tests/amr/amr_test.c index 2f41fe9..fabf948 100644 --- a/tests/amr/amr_test.c +++ b/tests/amr/amr_test.c @@ -46,7 +46,7 @@ char *oa_amr_samples[] = { "100c1fb967f7f1fdf547bf2e61c060", "0004f89d67f1160935bde1996840", "0004633cc7f0630439ffe0000000", - "0004eb81fc0758973b9edc782552", + "0004eb81fc0758973b9edc782550", "a078ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00fc", /* sample with invalid FT */ "END", }; diff --git a/tests/amr/amr_test.ok b/tests/amr/amr_test.ok index af1be82..eea513b 100644 --- a/tests/amr/amr_test.ok +++ b/tests/amr/amr_test.ok @@ -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 |