unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Josep Portella Florit <jpf@primfilat.com>
Cc: 22667@debbugs.gnu.org, "Ludovic Courtès" <ludo@gnu.org>
Subject: bug#22667: string->bytevector encoding error
Date: Thu, 03 Mar 2016 12:55:55 -0500	[thread overview]
Message-ID: <87oaavsaxg.fsf@netris.org> (raw)
In-Reply-To: <56C0FD28.9050709@primfilat.com> (Josep Portella Florit's message of "Sun, 14 Feb 2016 23:18:16 +0100")

Josep Portella Florit <jpf@primfilat.com> writes:

> 'string->bytevector' throws 'encoding-error' when the encoding is
> "UTF-16" and the length of the string is greater than 128.  The same
> for the encoding "UTF-32" and a string of length greater than 64.
>
> Tested on Guile 2.0.11 and 2.1.2 with the same result.
>
> How to reproduce:
>
> (use-modules (ice-9 iconv))
>
> ;; These expressions evaluate as expected:
> (string->bytevector (make-string 128 #\A) "UTF-16")
> ;; => #vu8(254 255 0 65 0 65 ...)
> (string->bytevector (make-string 64 #\A) "UTF-32")
> ;; => #vu8(0 0 254 255 0 0 0 65 0 0 0 65 ...)
>
> ;; These expressions throw 'encoding-error':
> (string->bytevector (make-string 129 #\A) "UTF-16")
> (string->bytevector (make-string 65 #\A) "UTF-32")

Thee bug is in 'display_string_using_iconv', introduced in commit
f4bc4e5934, which improperly assumes that a 256-byte buffer
(encoded_output) will be large enough to hold the results of converting
up to 256 bytes of UTF-8 (utf8_buf) to an arbitrary encoding using
'iconv'.  When this assumption fails, the call to 'iconv' on line 997

      done = iconv (id->output_cd, &input, &input_left,
		    &output, &output_left);

reports a failure due to the output buffer being too small, and the code
fails to handle this case.

To be continued...

     Mark





  reply	other threads:[~2016-03-03 17:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-14 22:18 bug#22667: string->bytevector encoding error Josep Portella Florit
2016-03-03 17:55 ` Mark H Weaver [this message]
2016-06-20 16:07 ` Andy Wingo
2016-08-07 21:25   ` Andy Wingo

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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oaavsaxg.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=22667@debbugs.gnu.org \
    --cc=jpf@primfilat.com \
    --cc=ludo@gnu.org \
    /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).