From 96397778144722f7983774e9fc88521f4d36d3c7 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sat, 24 Oct 2020 19:06:41 +0200 Subject: Fix validation of overlong UTF-8 It was too strict and Egyptian dicks didn't want to pass, so we'll do it half-arsedly for a subset. --- liberty.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'liberty.c') diff --git a/liberty.c b/liberty.c index 1695fd3..9705081 100644 --- a/liberty.c +++ b/liberty.c @@ -2748,16 +2748,12 @@ utf8_decode (const char **s, size_t len) } // In the middle of a character - if (sequence_len == 1) + // or an overlong sequence (subset, possibly MUTF-8, not supported) + if (sequence_len == 1 || *p == 0xC0 || *p == 0xC1) return -1; // Check the rest of the sequence uint32_t cp = *p++ & ~mask; - - // Overlong sequence (possibly MUTF-8, not supported) - if (!cp && sequence_len) - return -1; - while (sequence_len && --sequence_len) { if (p == end) -- cgit v1.2.3-70-g09d2