public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix iconv from SHIFT-JIS
Date: Fri, 24 Apr 2009 16:15:00 -0000	[thread overview]
Message-ID: <20090424162458.GA16681@sunsite.ms.mff.cuni.cz> (raw)

Hi!

As can be seen on the https://bugzilla.redhat.com/show_bug.cgi?id=497267
testcase, sjis.c handles invalid 2 byte inputs incorrectly, inptr += 2
shouldn't be done before STANDARD_FROM_LOOP_ERR_HANDLER (2).
The code does:
if (something)
  STANDARD_FROM_LOOP_ERR_HANDLER (1);
else
  {
    if (...)
      ch = ...
    else...
      ch = ...
    inptr += 2;
  }
if (ch == 0)
  STANDARD_FROM_LOOP_ERR_HANDLER (2);

As STANDARD_FROM_LOOP_ERR_HANDLER never falls through (either does break
or continue), we can move the second S_F_L_E_H into the else and it really
has to be done before the inptr += 2, otherwise when stopping on errors
we move over the invalid 2 byte sequence and when ignoring errors
skip over 4 bytes instead of 2.
Also, I believe we should skip over 2 bytes instead of 1 when ignoring
errors for say \xea\xaf, instead of trying to convert the second byte as
start of a character.

2009-04-24  Jakub Jelinek  <jakub@redhat.com>

	* iconvdata/sjis.c (BODY): Don't advance inptr before
	STANDARD_FROM_LOOP_ERR_HANDLER (2) for 2 byte invalid input.
	Use STANDARD_FROM_LOOP_ERR_HANDLER with 2 instead of 1 for
	two byte chars.

--- libc/iconvdata/sjis.c.jj	2002-12-02 23:07:56.000000000 +0100
+++ libc/iconvdata/sjis.c	2009-04-24 18:09:01.000000000 +0200
@@ -1,5 +1,5 @@
 /* Mapping tables for SJIS handling.
-   Copyright (C) 1997-2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1997-2001, 2002, 2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 
@@ -4379,7 +4379,7 @@ static const char from_ucs4_extra[0x100]
 	    || __builtin_expect (idx > 0xeaa4, 0))			      \
 	  {								      \
 	    /* This is illegal.  */					      \
-	    STANDARD_FROM_LOOP_ERR_HANDLER (1);				      \
+	    STANDARD_FROM_LOOP_ERR_HANDLER (2);				      \
 	  }								      \
 	else								      \
 	  {								      \
@@ -4395,14 +4395,15 @@ static const char from_ucs4_extra[0x100]
 	    else							      \
 	      ch = cjk_block4[(ch - 0xe0) * 192 + ch2 - 0x40];		      \
 									      \
+	    if (__builtin_expect (ch == 0, 0))				      \
+	      {								      \
+		/* This is an illegal character.  */			      \
+		STANDARD_FROM_LOOP_ERR_HANDLER (2);			      \
+	      }								      \
+									      \
 	    inptr += 2;							      \
 	  }								      \
 									      \
-	if (__builtin_expect (ch == 0, 0))				      \
-	  {								      \
-	    /* This is an illegal character.  */			      \
-	    STANDARD_FROM_LOOP_ERR_HANDLER (2);				      \
-	  }								      \
       }									      \
 									      \
     put32 (outptr, ch);							      \

	Jakub

                 reply	other threads:[~2009-04-24 16:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20090424162458.GA16681@sunsite.ms.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.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).