[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Corrupted contedt when using utf-8 with Hebrew values in XML

In my previous conclusion I didn't pay attention to iconv() documentation
that says:
"The variable (pointer) is updated to point to the byte following the last
byte successfully used in the conversion."

However, it says also "If an error occurs during one of the following
requested conversions, the inbuf, inbytesleft, outbuf, and outbytesleft
parameters may not be updated properly."

So, what we have to do is check if p_Data (input pointer) is updated by
iconv(). If not, we have to increment it by the number of bytes already

it seems to me that the right code of iconvdyn() procedure should be:
(comment = Boaz, are my suggestion for fixes )

P iconvdyn        B                   export

D iconvdyn        PI            10I 0

D   peSize                      10I 0 value

D   peData                        *   value

D   peDesc                      52a

D   peOutbuf                      *


D len             s             10I 0

 /if not defined(HTTP_USE_TABLES)

D insize          s             10U 0

D desc            s                   like(ToAscii)

D p_Data          s               *
D p_outbuf        s               *

D size            s             10U 0

D spaceleft       s             10U 0

D GROW_CHUNK      C                   const(65536)


d Ptr@            s               *
boaz save p_Data    

D                 ds

D rcU                           10U 0

D rcI                           10I 0 overlay(rcU)


c                   eval      insize    = peSize

c                   eval      size      = insize

c                   eval      peOutbuf  = xalloc(size)

c                   eval      p_outbuf  = peOutbuf

c                   eval      p_Data = peData
c                   eval      spaceleft = size


c                   dow       '1'


c                   eval      Ptr@ = p_Data

c                   eval      rcU = iconv( peDesc

c                                        : p_Data
c                                        : insize

c                                        : p_outbuf

c                                        : spaceleft )


c                   if        rcI >= 0

c                   leave

c                   endif


c                   if        errno <> E2BIG

c                   callp     SetError( HTTP_CONVERR

c                                     : 'CCSID conversion failed: '

c                                     + %str(strerror(errno)) )

c                   callp     xdealloc(peOutbuf)

c                   return    -1

c                   endif


c                   eval      size      = size + GROW_CHUNK

c                   eval      len       = p_outbuf - peOutbuf

c                   eval      peOutbuf  = xrealloc(peOutbuf:size)

c                   eval      p_outbuf  = peOutbuf + len

c                   eval      spaceleft = size - len


c                   if        ptr@ = p_Data
c                   eval      p_Data = peData
Boaz skip over     
c                                    + (peSize - insize)
converted data    
c                   endif

c                   enddo


c                   eval      len = size - spaceleft


c                   return    len

P                 E

Hope this is the right solution to avoid the corruption when going from
single byte code page to multi bytes code page.

Boaz Mermelstein
3/21 Hershko Avraham st. |  Rehovot   |  Israel
Phone: +972 8 9458690  |  Mobile:+972 54 4441 891  |  Fax: +972 151 54 4441

This is the FTPAPI mailing list.  To unsubscribe, please go to: