Re: psql crashes on encoding mismatch

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Hitoshi Harada <umi.tanuki@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2011-01-13T05:22:32Z
Lists: pgsql-hackers
Hitoshi Harada <umi.tanuki@gmail.com> writes:
> I found a crash case (assertion failure) when runing psql -f
> utf8_encoded_script.sql against client_encoding = shift_jis in
> postgresql.conf. Though encoding mismatch is obviously user's fault, a
> crash doesn't explain anything to him.

I'm not too impressed with this patch: it seems like the most it will
accomplish is to move the failure to some other, equally obscure, place
--- because you'll still have a string that's invalidly encoded.
Moreover, if you've got wrongly encoded data, it wouldn't be hard at all
for it to mess up psql's lexing; consider cases such as a
character-that's-not-as-long-as-we-think just in front of a quote mark.

Shouldn't we instead try to verify the multibyte encoding somewhere
upstream of here?

			regards, tom lane