Bug 497267

Summary: Bug in SHIFT_JIS EILSEQ handling
Product: [Fedora] Fedora Reporter: Behdad Esfahbod <behdad>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: rawhideCC: jakub
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-04-27 20:11:21 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
test case none

Description Behdad Esfahbod 2009-04-23 05:18:29 UTC
Trying to convert the invalid sequence "\x98\x8c" from SHIFT_JIS to UTF-8, iconv correctly returns -1 and sets errno to EILSEQ, however it advances input pointers, consuming the ill sequence.  It should not.

This is causing gnome-terminal to crash seeing that sequence at the end of input.  I'm fixing the crasher in g-t, but the real bug is in iconv.  g-t bug:
http://bugzilla.gnome.org/show_bug.cgi?id=567064

Attaching test case.

Comment 1 Jakub Jelinek 2009-04-23 10:22:31 UTC
Testcase is missing...

Comment 2 Jakub Jelinek 2009-04-23 10:32:55 UTC
I've tried:
#include <iconv.h>
#include <assert.h>
#include <errno.h>

int
main (void)
{
  iconv_t i1 = iconv_open ("ISO-8859-1//", "UTF-8//");
  iconv_t i2 = iconv_open ("UTF-8//", "SHIFT-JIS//");
  char *inbuf, *outbuf, buf[64];
  size_t inbytesleft, outbytesleft, res;

  inbuf = "\x83\x83\x83";
  inbytesleft = 3;
  outbuf = buf;
  outbytesleft = 64;
  errno = 0;
  res = iconv (i1, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
  assert (res == (size_t) -1 && errno == EILSEQ && inbytesleft == 3 && outbytesleft == 64);

  inbuf = "\xec\x98\x8c";
  inbytesleft = 3;
  outbuf = buf;
  outbytesleft = 64;
  errno = 0;
  res = iconv (i2, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
  assert (res == (size_t) -1 && errno == EILSEQ && inbytesleft == 3 && outbytesleft == 64);

  return 0;
}

but that works as expected.

Comment 3 Behdad Esfahbod 2009-04-23 22:51:47 UTC
Created attachment 341034 [details]
test case

Sorry.  I'm sure I attached in the original report form...

Anyway, seems to work for "\xec\x98\x8c", but not for "x\x98\x8c".

Comment 4 Jakub Jelinek 2009-04-27 20:11:21 UTC
Should be fixed in glibc-2.9.90-22.

Comment 5 Behdad Esfahbod 2009-04-27 20:21:49 UTC
Thanks.