public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: "Никита Попов via Libc-alpha" <libc-alpha@sourceware.org>
Cc: "Никита Попов" <npv1310@gmail.com>
Subject: Re: [PATCH] gconv: Do not emit spurious NUL character in ISO-2022-JP-3 (bug 28524)
Date: Thu, 04 Nov 2021 15:10:18 +0100	[thread overview]
Message-ID: <87ee7wf1v9.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <CA+cA0PCy0XyvZLXYiKKz7GwQcYRCoU-8AFp8tf1sLCTAUsON=Q@mail.gmail.com> (=?utf-8?B?ItCd0LjQutC40YLQsCDQn9C+0L/QvtCy?= via Libc-alpha"'s message of "Tue, 2 Nov 2021 14:06:58 +0500")

* Никита Попов via Libc-alpha:

> To eliminate this issue, these steps are taken:
> * Restore original condition
> '(data->__statep->__count & ~7) != ASCII_set'.
> It is necessary since bits 0-2 may contain
> number of buffered input characters.

Right, I missed that use of __count by the framework. 8-/

> * Check that queued character is not NUL.
> Similar step is taken for main conversion loop.

And since EMIT_SHIFT_TO_INIT runs before the loop, it's necessary to
mirror that logic there.

> diff --git a/iconvdata/bug-iconv15.c b/iconvdata/bug-iconv15.c
> new file mode 100644
> index 0000000000..4037e131ff

> +  /* First call to iconv should alter internal state.
> +     Now, JISX0201_Kana_set is selected and
> +     state value != ASCII_set */

Sorry, GNU style says that comments should end with ”.  */” (period and
two spaces).

> +  TEST_VERIFY (iconv (cd, &inbuf, &inleft, &outbuf, &outleft) != (size_t) -1);

Can we add an additional test here?  I think no bytes have been added to
the output at this point, right?

> +  /* Second call shall emit spurious NUL character in unpatched glibc. */

> +  /* No characters are expected to be produced. */

Missing space after ”.” (see above).

> diff --git a/iconvdata/iso-2022-jp-3.c b/iconvdata/iso-2022-jp-3.c
> index 70b28ace7f..5e66d686f1 100644
> --- a/iconvdata/iso-2022-jp-3.c
> +++ b/iconvdata/iso-2022-jp-3.c
> @@ -79,20 +79,31 @@ enum
>     the output state to the initial state.  This has to be done during the
>     flushing.  */
>  #define EMIT_SHIFT_TO_INIT \
> -  if (data->__statep->__count != ASCII_set)			      \
> +  if ((data->__statep->__count & ~7) != ASCII_set)			      \
>      {									      \
>        if (FROM_DIRECTION)						      \
>  	{								      \
> -	  if (__glibc_likely (outbuf + 4 <= outend))			      \
> +	  uint32_t ch = data->__statep->__count >> 6;			      \
> +									      \
> +	  if (__glibc_unlikely (ch != 0))				      \
>  	    {								      \
> -	      /* Write out the last character.  */			      \
> -	      *((uint32_t *) outbuf) = data->__statep->__count >> 6;	      \
> -	      outbuf += sizeof (uint32_t);				      \
> -	      data->__statep->__count = ASCII_set;			\
> +	      if (__glibc_likely (outbuf + 4 <= outend))		      \
> +		{							      \
> +		  /* Write out the last character.  */			      \
> +		  put32u (outbuf, ch);					      \
> +		  outbuf += 4;						      \
> +		  data->__statep->__count &= 7;				      \
> +		  data->__statep->__count |= ASCII_set;			      \
> +		}							      \
> +	      else							      \
> +		/* We don't have enough room in the output buffer.  */	      \
> +		status = __GCONV_FULL_OUTPUT;				      \
>  	    }								      \
>  	  else								      \
> -	    /* We don't have enough room in the output buffer.  */	      \
> -	    status = __GCONV_FULL_OUTPUT;				      \
> +	    {								      \
> +	      data->__statep->__count &= 7;				      \
> +	      data->__statep->__count |= ASCII_set;			      \
> +	    }								      \
>  	}								      \
>        else								      \
>  	{								      \

The actual code change looks okay to me.

Thanks,
Florian


  parent reply	other threads:[~2021-11-04 14:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-02  9:06 Никита Попов
2021-11-03  4:20 ` Никита Попов
2021-11-04 14:10 ` Florian Weimer [this message]
2021-11-04 14:32 ` Florian Weimer
2021-11-04 15:03   ` Никита Попов
2021-11-04 19:34     ` Florian Weimer

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=87ee7wf1v9.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=npv1310@gmail.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).