From: Junio C Hamano <gitster@pobox.com>
To: Lars Schneider <larsxschneider@gmail.com>
Cc: "Lars Schneider" <lars.schneider@autodesk.com>,
git <git@vger.kernel.org>, "Torsten Bögershausen" <tboegi@web.de>,
"Johannes Sixt" <j6t@kdbg.org>,
"Eric Sunshine" <sunshine@sunshineco.com>,
"Jeff King" <peff@peff.net>,
ramsay@ramsayjones.plus.com, Johannes.Schindelin@gmx.de
Subject: Re: [PATCH v9 6/8] convert: check for detectable errors in UTF encodings
Date: Mon, 05 Mar 2018 17:23:32 -0800 [thread overview]
Message-ID: <xmqqvaea6lpn.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <55633B6F-EB6E-42D6-8E58-79158A99774A@gmail.com> (Lars Schneider's message of "Tue, 6 Mar 2018 00:45:02 +0100")
Lars Schneider <larsxschneider@gmail.com> writes:
>> On 05 Mar 2018, at 22:50, Junio C Hamano <gitster@pobox.com> wrote:
>>
>> lars.schneider@autodesk.com writes:
>>
>>> +static int validate_encoding(const char *path, const char *enc,
>>> + const char *data, size_t len, int die_on_error)
>>> +{
>>> + if (!memcmp("UTF-", enc, 4)) {
>>
>> Does the caller already know that enc is sufficiently long that
>> using memcmp is safe?
>
> No :-(
>
> Would you be willing to squash that in?
>
> if (strlen(enc) > 4 && !memcmp("UTF-", enc, 4)) {
>
> I deliberately used "> 4" as plain "UTF-" is not even valid.
I'd rather not. The code does not have to even look at 6th and
later bytes in the enc[] even if it wanted to reject "UTF-" followed
by nothing, but use of strlen() forces it to look at everything.
Stepping back, shouldn't
if (starts_with(enc, "UTF-")
be sufficient? If you really care about the case where "UTF-" alone
comes here, you could write
if (starts_with(enc, "UTF-") && enc[4])
but I do not think "&& enc[4]" is even needed. The functions called
from this block would not consider "UTF-" alone as something valid
anyway, so with that "&& enf[4]" we would be piling more code only
for invalid/rare case.
next prev parent reply other threads:[~2018-03-06 1:23 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-04 20:14 [PATCH v9 0/8] convert: add support for different encodings lars.schneider
2018-03-04 20:14 ` [PATCH v9 1/8] strbuf: remove unnecessary NUL assignment in xstrdup_tolower() lars.schneider
2018-03-04 20:14 ` [PATCH v9 2/8] strbuf: add xstrdup_toupper() lars.schneider
2018-03-04 20:14 ` [PATCH v9 3/8] utf8: add function to detect prohibited UTF-16/32 BOM lars.schneider
2018-03-04 20:14 ` [PATCH v9 4/8] utf8: add function to detect a missing " lars.schneider
2018-03-06 20:50 ` Junio C Hamano
2018-03-06 22:39 ` Lars Schneider
2018-03-06 22:53 ` Junio C Hamano
2018-03-06 23:00 ` Lars Schneider
2018-03-06 23:07 ` Junio C Hamano
2018-03-06 23:12 ` Lars Schneider
2018-03-06 23:37 ` Junio C Hamano
2018-03-07 17:39 ` Torsten Bögershausen
2018-03-04 20:14 ` [PATCH v9 5/8] convert: add 'working-tree-encoding' attribute lars.schneider
2018-03-06 20:42 ` Eric Sunshine
2018-03-06 22:13 ` Lars Schneider
2018-03-06 22:22 ` Eric Sunshine
2018-03-04 20:14 ` [PATCH v9 6/8] convert: check for detectable errors in UTF encodings lars.schneider
2018-03-05 21:50 ` Junio C Hamano
2018-03-05 23:45 ` Lars Schneider
2018-03-06 1:23 ` Junio C Hamano [this message]
2018-03-06 17:03 ` Lars Schneider
2018-03-06 20:55 ` Eric Sunshine
2018-03-04 20:14 ` [PATCH v9 7/8] convert: add tracing for 'working-tree-encoding' attribute lars.schneider
2018-03-04 20:14 ` [PATCH v9 8/8] convert: add round trip check based on 'core.checkRoundtripEncoding' lars.schneider
2018-03-06 21:05 ` [PATCH v9 0/8] convert: add support for different encodings Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqvaea6lpn.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
--cc=lars.schneider@autodesk.com \
--cc=larsxschneider@gmail.com \
--cc=peff@peff.net \
--cc=ramsay@ramsayjones.plus.com \
--cc=sunshine@sunshineco.com \
--cc=tboegi@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).