[riot-notifications] [RIOT-OS/RIOT] sys/base64: cannot handle zero length buffers (#12213)

Juan I Carrano notifications at github.com
Thu Sep 12 16:59:33 CEST 2019


#### Description

According to [RFC4648, section 10](https://tools.ietf.org/html/rfc4648#section-10) a zero length vector is encoded to a zero length string and vice-versa.

The base64 implementation cannot handle this and reports a BASE64_ERROR_DATA_IN_SIZE.

Interestingly, this trivial test case was missing from the unit tests, as are all of the other "official" RFC test vectors.

#### Steps to reproduce the issue

Apply this patch to the unit tests:

<details>
 <summary>Patch</summary>

```diff
diff --git a/tests/unittests/tests-base64/tests-base64.c b/tests/unittests/tests-base64/tests-base64.c
index 762b1d972..36326ee4f 100644
--- a/tests/unittests/tests-base64/tests-base64.c
+++ b/tests/unittests/tests-base64/tests-base64.c
@@ -61,6 +61,32 @@ static void test_base64_01_encode_string(void)
 #endif
 }

+static void test_base64_trivial_fw(void)
+{
+    unsigned char data_in[] = "";
+
+    size_t base64_out_size = 8;
+    unsigned char base64_out[8];
+
+    int ret = base64_encode(data_in, 0, base64_out, &base64_out_size);
+
+    TEST_ASSERT_EQUAL_INT(BASE64_SUCCESS, ret);
+    TEST_ASSERT_EQUAL_INT(0, base64_out_size);
+}
+
+static void test_base64_trivial_bw(void)
+{
+    unsigned char data_in[] = "";
+
+    size_t base64_out_size = 8;
+    unsigned char base64_out[8];
+
+    int ret = base64_decode(data_in, 0, base64_out, &base64_out_size);
+
+    TEST_ASSERT_EQUAL_INT(BASE64_SUCCESS, ret);
+    TEST_ASSERT_EQUAL_INT(0, base64_out_size);
+}
+
 static void test_base64_02_decode_base64(void)
 {
     unsigned char encoded_base64[] = "SGVsbG8gUklPVCB0aGlzIGlzIGEgYmFzZTY0IHRlc3Q"
@@ -386,6 +412,8 @@ static void test_base64_09_encode_size_determination(void)
 Test *tests_base64_tests(void)
 {
     EMB_UNIT_TESTFIXTURES(fixtures) {
+        new_TestFixture(test_base64_trivial_fw),
+        new_TestFixture(test_base64_trivial_bw),
         new_TestFixture(test_base64_01_encode_string),
         new_TestFixture(test_base64_02_decode_base64),
         new_TestFixture(test_base64_03_single_character),
```

</details>

#### Expected results

Test passes.

#### Actual results

```
main(): This is RIOT! (Version: 2019.10-devel-764-g23c18-up-)
..
base64_tests.test_base64_trivial_fw (tests/unittests/tests-base64/tests-base64.c 73) exp 0 was -4
..
base64_tests.test_base64_trivial_bw (tests/unittests/tests-base64/tests-base64.c 86) exp 0 was -4
.........
run 11 failures 2
```


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/issues/12213
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190912/9f2e26dc/attachment.htm>


More information about the notifications mailing list