From c3ce44d4acc24a516a1fe3bd8ce5799c09ac1f14 Mon Sep 17 00:00:00 2001 From: Jan Olaf Krems Date: Fri, 30 Sep 2022 06:59:46 -0700 Subject: [PATCH 1/2] Fix out-of-bounds access in test --- test/test_base64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_base64.c b/test/test_base64.c index bec52d14..52bb3190 100644 --- a/test/test_base64.c +++ b/test/test_base64.c @@ -195,7 +195,7 @@ test_streaming (int flags) base64_stream_decode_init(&state, flags); memset(enc, 0, 400); - while (base64_stream_decode(&state, &ref[inpos], (inpos + bs > reflen) ? reflen - inpos : bs, &enc[enclen], &partlen)) { + while (inpos < 400 && base64_stream_decode(&state, &ref[inpos], (inpos + bs > reflen) ? reflen - inpos : bs, &enc[enclen], &partlen)) { enclen += partlen; inpos += bs; } From c412dac5c3d462763b1d7865fddb6526a06ca8f2 Mon Sep 17 00:00:00 2001 From: Jan Olaf Krems Date: Thu, 13 Oct 2022 05:43:27 -0700 Subject: [PATCH 2/2] fixup! Fix out-of-bounds access in test --- test/test_base64.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/test_base64.c b/test/test_base64.c index 52bb3190..ee8d7068 100644 --- a/test/test_base64.c +++ b/test/test_base64.c @@ -195,9 +195,14 @@ test_streaming (int flags) base64_stream_decode_init(&state, flags); memset(enc, 0, 400); - while (inpos < 400 && base64_stream_decode(&state, &ref[inpos], (inpos + bs > reflen) ? reflen - inpos : bs, &enc[enclen], &partlen)) { + while (base64_stream_decode(&state, &ref[inpos], (inpos + bs > reflen) ? reflen - inpos : bs, &enc[enclen], &partlen)) { enclen += partlen; inpos += bs; + + // Has the entire buffer been consumed? + if (inpos >= 400) { + break; + } } if (enclen != 256) { printf("FAIL: stream decoding gave incorrect size: "