+2023-10-26 Pádraig Brady <P@draigBrady.com>
+
+ base32, base64: disallow non-canonical encodings
+ * lib/base32.c: Check that discarded bits in the encoding are zero.
+ * lib/base64.c: Likewise.
+ * tests/test-base32.c: Add test cases.
+ * tests/test-base64.c: Likewise.
+
2023-10-26 Bruno Haible <bruno@clisp.org>
fenv: Add tests.
if (in[3] != '=' || in[4] != '=' || in[5] != '='
|| in[6] != '=' || in[7] != '=')
return_false;
+
+ /* Reject non-canonical encodings. */
+ if (base32_to_int[to_uchar (in[1])] & 0x03)
+ return_false;
}
else
{
{
if (in[5] != '=' || in[6] != '=' || in[7] != '=')
return_false;
+
+ /* Reject non-canonical encodings. */
+ if (base32_to_int[to_uchar (in[3])] & 0x0f)
+ return_false;
}
else
{
{
if (in[6] != '=' || in[7] != '=')
return_false;
+
+ /* Reject non-canonical encodings. */
+ if (base32_to_int[to_uchar (in[4])] & 0x01)
+ return_false;
}
else
{
--*outleft;
}
}
+ else
+ {
+ /* Reject non-canonical encodings. */
+ if (base32_to_int[to_uchar (in[6])] & 0x07)
+ return_false;
+ }
}
}
}
if (in[3] != '=')
return_false;
+
+ /* Reject non-canonical encodings. */
+ if (base64_to_int[to_uchar (in[1])] & 0x0f)
+ return_false;
}
else
{
{
if (inlen != 4)
return_false;
+
+ /* Reject non-canonical encodings. */
+ if (base64_to_int[to_uchar (in[2])] & 0x03)
+ return_false;
}
else
{
ok = base32_decode_alloc_ctx (NULL, "AABBAA=A", 8, &p, &len);
ASSERT (!ok);
+ ok = base32_decode_alloc_ctx (NULL, "FZ======", 8, &p, &len);
+ ASSERT (!ok);
+
+ ok = base32_decode_alloc_ctx (NULL, "FYXB====", 8, &p, &len);
+ ASSERT (!ok);
+
+ ok = base32_decode_alloc_ctx (NULL, "FYXC5===", 8, &p, &len);
+ ASSERT (!ok);
+
+ ok = base32_decode_alloc_ctx (NULL, "FYXC4LR=", 8, &p, &len);
+ ASSERT (!ok);
+
+ ok = base32_decode_alloc_ctx (NULL, "FZ======FY======", 16, &p, &len);
+ ASSERT (!ok);
+
return 0;
}
ok = base64_decode_alloc_ctx (NULL, "aax=X", 5, &p, &len);
ASSERT (!ok);
+ ok = base64_decode_alloc_ctx (NULL, "SGVsbG9=", 8, &p, &len);
+ ASSERT (!ok);
+
+ ok = base64_decode_alloc_ctx (NULL, "TR==", 4, &p, &len);
+ ASSERT (!ok);
+
+ ok = base64_decode_alloc_ctx (NULL, "TWF=TWE=", 8, &p, &len);
+ ASSERT (!ok);
+
return 0;
}