From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by sourceware.org (Postfix) with ESMTPS id 892763858287 for ; Wed, 9 Nov 2022 02:11:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 892763858287 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=kitware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kitware.com Received: by mail-qk1-x72c.google.com with SMTP id p18so5676731qkg.2 for ; Tue, 08 Nov 2022 18:11:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kitware.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FmQARJR0+/Ox6vGEg4VaTuSXbISaHDilZGoCgwFhBBk=; b=OX6DBDb+b6ye6rABYXPl4PCN92Y6xB40lkNw2mTApeuo/p7XJSHbeorARGdNSjuXfM Vr1mQk24B3lmXSDqNrm4gI+yfPVKr/xLLuNpoQLKz8x09SZpbKs1K7sdQmQ03acovXpu YA9BmCdgUhDyZw4jQml/0MNPMECyj8BM1O32E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FmQARJR0+/Ox6vGEg4VaTuSXbISaHDilZGoCgwFhBBk=; b=krV85Vc0ol3j86AM+Y+lsTDlyiupZXQ0aYW19O+UpR+OUXG1EX/ArqwEXVUclreLIi BixmsIDOHPl7ucVnfDBCZ7HxIF9vV6dAg6FB6tUAwkD+Lf95CeiCvSlwfi4Z06sxTyL/ 6ZMIDJ/ujBOZaHVLiOkcu9myk7QPzUKFl9Woe8GGH/I+Rc8rju/Rmab1HD234puURB5c L00fxf1FFLEgDpb9XN9nTimBwrYqV0E/qWOhJ2xUdi4jcM47G3NPCgnZXhEMrbc0sjku YLgb+kTU1Vo2rMUN9lSzDrkNgIfdnWpnZ7rNtmutKhe0vIN/MY8ax3OjsF9Lf1sUG7Mr J/pw== X-Gm-Message-State: ACrzQf3gyqIlaazMlF2BsoLfgRZP2a0uVUy627xlpW8NroM/6YcBs77/ B05x/S1htaPLX/B1h6IRq2wmBvhV+ewNvw== X-Google-Smtp-Source: AMsMyM4jqj9hiZ617BMRheMZp0Jtd+M0WaQi3MBftSpjIM8rHRDJxAIxfHuPBpUCsLTSYNdYhIiEnQ== X-Received: by 2002:ae9:ed06:0:b0:6f9:efd2:9b96 with SMTP id c6-20020ae9ed06000000b006f9efd29b96mr43302844qkg.651.1667959860858; Tue, 08 Nov 2022 18:11:00 -0800 (PST) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id gd11-20020a05622a5c0b00b00398d83256ddsm9158014qtb.31.2022.11.08.18.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 18:11:00 -0800 (PST) From: Ben Boeckel To: gcc-patches@gcc.gnu.org Cc: Ben Boeckel , jason@redhat.com, nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com Subject: [PATCH v3 1/3] libcpp: reject codepoints above 0x10FFFF Date: Tue, 8 Nov 2022 21:10:46 -0500 Message-Id: <20221109021048.2123704-2-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221109021048.2123704-1-ben.boeckel@kitware.com> References: <20221109021048.2123704-1-ben.boeckel@kitware.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Unicode does not support such values because they are unrepresentable in UTF-16. libcpp/ * charset.cc: Reject encodings of codepoints above 0x10FFFF. UTF-16 does not support such codepoints and therefore all Unicode rejects such values. Signed-off-by: Ben Boeckel --- libcpp/charset.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libcpp/charset.cc b/libcpp/charset.cc index 12a398e7527..324b5b19136 100644 --- a/libcpp/charset.cc +++ b/libcpp/charset.cc @@ -158,6 +158,10 @@ struct _cpp_strbuf encoded as any of DF 80, E0 9F 80, F0 80 9F 80, F8 80 80 9F 80, or FC 80 80 80 9F 80. Only the first is valid. + Additionally, Unicode declares that all codepoints above 0010FFFF are + invalid because they cannot be represented in UTF-16. As such, all 5- and + 6-byte encodings are invalid. + An implementation note: the transformation from UTF-16 to UTF-8, or vice versa, is easiest done by using UTF-32 as an intermediary. */ @@ -216,7 +220,7 @@ one_utf8_to_cppchar (const uchar **inbufp, size_t *inbytesleftp, if (c <= 0x3FFFFFF && nbytes > 5) return EILSEQ; /* Make sure the character is valid. */ - if (c > 0x7FFFFFFF || (c >= 0xD800 && c <= 0xDFFF)) return EILSEQ; + if (c > 0x10FFFF || (c >= 0xD800 && c <= 0xDFFF)) return EILSEQ; *cp = c; *inbufp = inbuf; @@ -320,7 +324,7 @@ one_utf32_to_utf8 (iconv_t bigend, const uchar **inbufp, size_t *inbytesleftp, s += inbuf[bigend ? 2 : 1] << 8; s += inbuf[bigend ? 3 : 0]; - if (s >= 0x7FFFFFFF || (s >= 0xD800 && s <= 0xDFFF)) + if (s > 0x10FFFF || (s >= 0xD800 && s <= 0xDFFF)) return EILSEQ; rval = one_cppchar_to_utf8 (s, outbufp, outbytesleftp); -- 2.38.1