Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

UTF-16 surrogate message when writing binary data (image)

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


m.e at acm

May 8, 2008, 11:58 PM

Post #1 of 6 (93 views)
Permalink
UTF-16 surrogate message when writing binary data (image)

If I write binary data (a JPEG) using $c->res->body then I get all these
errors

stderr: UTF-16 surrogate 0xdf98 at /usr/lib/perl/5.8/IO/Handle.pm line 199.

My code looks like

$c->res->content_type(q{image/jpeg});
$c->res->header( 'Content-Disposition', q{inline} );
$c->res->body($pic_image);

Presumably, something is assuming that the output is Unicode text and trying
to interpret it accordingly. These error messages are all over the log,
making it difficult to read, besides any impact the situation may be having
on the output.

Is there any way to fix this issue (eg something like binmode)?
--
Regards,
Martin
(m.e[at]acm.org)
IT: http://methodsupport.com Personal: http://thereisnoend.org


pagaltzis at gmx

May 9, 2008, 5:51 AM

Post #2 of 6 (79 views)
Permalink
Re: UTF-16 surrogate message when writing binary data (image) [In reply to]

* Martin Ellison <m.e[at]acm.org> [2008-05-09 14:46]:
> My code looks like
>
> $c->res->content_type(q{image/jpeg});
> $c->res->header( 'Content-Disposition', q{inline} );
> $c->res->body($pic_image);

Is `$pic_image` marked as a character string? Are you using
Catalyst::Plugin::Unicode?

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


m.e at acm

May 9, 2008, 6:53 AM

Post #3 of 6 (78 views)
Permalink
Re: Re: UTF-16 surrogate message when writing binary data (image) [In reply to]

my $p = new Image::Magick;
... lots of code
my $pic_image = $p->ImageToBlob();

I'm not sure if that makes it a character string but surely not?

I am using the Unicode plugin; does it cause any problems?

2008/5/9 Aristotle Pagaltzis <pagaltzis[at]gmx.de>:

> * Martin Ellison <m.e[at]acm.org> [2008-05-09 14:46]:
> > My code looks like
> >
> > $c->res->content_type(q{image/jpeg});
> > $c->res->header( 'Content-Disposition', q{inline} );
> > $c->res->body($pic_image);
>
> Is `$pic_image` marked as a character string? Are you using
> Catalyst::Plugin::Unicode?
>
> Regards,
> --
> Aristotle Pagaltzis // <http://plasmasturm.org/>
>
> _______________________________________________
> List: Catalyst[at]lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>



--
Regards,
Martin
(m.e[at]acm.org)
IT: http://methodsupport.com Personal: http://thereisnoend.org


pagaltzis at gmx

May 9, 2008, 8:35 AM

Post #4 of 6 (75 views)
Permalink
Re: UTF-16 surrogate message when writing binary data (image) [In reply to]

* Martin Ellison <m.e[at]acm.org> [2008-05-09 16:05]:
> my $p = new Image::Magick;
> ... lots of code
> my $pic_image = $p->ImageToBlob();
>
> I'm not sure if that makes it a character string but surely
> not?

Probably not, hmm.

> I am using the Unicode plugin; does it cause any problems?

It does not cause the problem, exactly, but it will expose
problems in other code if there are. What it does is if the
response body is a character string, it will encode it to
yield a byte string.

But I just realised that you if are getting the warning from
IO::Handle, then the Unicode plugin probably has nothing to do
with it.

Hmm. Maybe enable stack traces (Carp::Always or C:P:StackTrace or
whatever) and then trigger the warning after making all warnings
fatal to force a crash? That way you would find out where in the
Catalyst guts the problem occurs, so you can get an idea of what
a fix might look like.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


dbix-class at trout

May 10, 2008, 7:05 AM

Post #5 of 6 (68 views)
Permalink
Re: UTF-16 surrogate message when writing binary data (image) [In reply to]

On Fri, May 09, 2008 at 02:58:41PM +0800, Martin Ellison wrote:
> If I write binary data (a JPEG) using $c->res->body then I get all these
> errors
>
> stderr: UTF-16 surrogate 0xdf98 at /usr/lib/perl/5.8/IO/Handle.pm line 199.
>
> My code looks like
>
> $c->res->content_type(q{image/jpeg});
> $c->res->header( 'Content-Disposition', q{inline} );
> $c->res->body($pic_image);
>
> Presumably, something is assuming that the output is Unicode text and trying
> to interpret it accordingly. These error messages are all over the log,
> making it difficult to read, besides any impact the situation may be having
> on the output.
>
> Is there any way to fix this issue (eg something like binmode)?

My best guess here is that $pic_image is, or looks like, a file handle,
and so when Catalyst is sending the response it's doing so by reading
from the filehandle and the error's turning up during $fh->read.

It'd of course be easier for you to confirm this, since you have the
copy of IO/Handle.pm and the line number - maybe you could look?

A good way to check would be to loop reading $pic_image yourself and
see if you get the same warning ...

--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


m.e at acm

May 12, 2008, 2:05 AM

Post #6 of 6 (51 views)
Permalink
Re: UTF-16 surrogate message when writing binary data (image) [In reply to]

The error is specifically at /usr/lib/perl/5.8/IO/Handle.pm line 199, which
is the second syswrite call in

sub syswrite {
@_ >= 2 && @_ <= 4 or croak 'usage: $io->syswrite(BUF [, LEN [,
OFFSET]])';
if (defined($_[2])) {
syswrite($_[0], $_[1], $_[2], $_[3] || 0);
} else {
syswrite($_[0], $_[1]);
}
}

The error is in production, so I am adding some trace code to investigate
further, but results will need to wait until I have pushed the code.

2008/5/10 Matt S Trout <dbix-class[at]trout.me.uk>:

> On Fri, May 09, 2008 at 02:58:41PM +0800, Martin Ellison wrote:
> > If I write binary data (a JPEG) using $c->res->body then I get all these
> > errors
> >
> > stderr: UTF-16 surrogate 0xdf98 at /usr/lib/perl/5.8/IO/Handle.pm line
> 199.
> >
> > My code looks like
> >
> > $c->res->content_type(q{image/jpeg});
> > $c->res->header( 'Content-Disposition', q{inline} );
> > $c->res->body($pic_image);
> >
> > Presumably, something is assuming that the output is Unicode text and
> trying
> > to interpret it accordingly. These error messages are all over the log,
> > making it difficult to read, besides any impact the situation may be
> having
> > on the output.
> >
> > Is there any way to fix this issue (eg something like binmode)?
>
> My best guess here is that $pic_image is, or looks like, a file handle,
> and so when Catalyst is sending the response it's doing so by reading
> from the filehandle and the error's turning up during $fh->read.
>
> It'd of course be easier for you to confirm this, since you have the
> copy of IO/Handle.pm and the line number - maybe you could look?
>
> A good way to check would be to loop reading $pic_image yourself and
> see if you get the same warning ...
>
> --
> Matt S Trout Need help with your Catalyst or DBIx::Class
> project?
> Technical Director
> http://www.shadowcat.co.uk/catalyst/
> Shadowcat Systems Ltd. Want a managed development or deployment
> platform?
> http://chainsawblues.vox.com/
> http://www.shadowcat.co.uk/servers/
>
> _______________________________________________
> List: Catalyst[at]lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>



--
Regards,
Martin
(m.e[at]acm.org)
IT: http://methodsupport.com Personal: http://thereisnoend.org

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.