[PATCH] gconv: Fix assertion failure in ISO-2022-JP-3 module (bug 27256)

Andreas Schwab schwab@linux-m68k.org
Wed Jan 27 13:30:48 GMT 2021


On Jan 27 2021, Florian Weimer via Libc-alpha wrote:

> diff --git a/iconvdata/iso-2022-jp-3.c b/iconvdata/iso-2022-jp-3.c
> index 3eaa847ad9..c8ba88cdc9 100644
> --- a/iconvdata/iso-2022-jp-3.c
> +++ b/iconvdata/iso-2022-jp-3.c
> @@ -67,23 +67,34 @@ enum
>    CURRENT_SEL_MASK = 7 << 3
>  };
>  
> -/* During UCS-4 to ISO-2022-JP-3 conversion, the COUNT element of the state
> -   also contains the last two bytes to be output, shifted by 6 bits, and a
> -   one-bit indicator whether they must be preceded by the shift sequence,
> -   in bit 22.  */
> +/* During UCS-4 to ISO-2022-JP-3 conversion, the COUNT element of the
> +   state also contains the last two bytes to be output, shifted by 6
> +   bits, and a one-bit indicator whether they must be preceded by the
> +   shift sequence, in bit 22.  During ISO-2022-JP-3 to UCS-4
> +   conversion, COUNT may also contain a non-zero pending wide
> +   character, shifted by six bits.  This happens for certain inputs in
> +   JISX0213_1_2004_set and JISX0213_2_set if the second wide character
> +   in a combining sequence cannot be written because the buffer is
> +   full.  */
>  
>  /* Since this is a stateful encoding we have to provide code which resets
>     the output state to the initial state.  This has to be done during the
>     flushing.  */
>  #define EMIT_SHIFT_TO_INIT \
> -  if ((data->__statep->__count & ~7) != ASCII_set)			      \
> +  if (data->__statep->__count != ASCII_set)			      \
>      {									      \
>        if (FROM_DIRECTION)						      \
>  	{								      \
> -	  /* It's easy, we don't have to emit anything, we just reset the     \
> -	     state for the input.  */					      \
> -	  data->__statep->__count &= 7;					      \
> -	  data->__statep->__count |= ASCII_set;				      \
> +	  if (__glibc_likely (outbuf + 4 <= outend))			      \
> +	    {								      \
> +	      /* Write out the last character.  */			      \
> +	      *((uint32_t *) outbuf) = data->__statep->__count >> 6;	      \

This should consistently use put32.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


More information about the Libc-alpha mailing list