pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid
3+ messages / 2 participants
[nested] [flat]

* BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid
@ 2015-06-10 14:32 Dmitri.Bourlatchkov@software.dell.com
  2015-08-05 03:32 ` Re: BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid Noah Misch <noah@leadboat.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Dmitri.Bourlatchkov@software.dell.com @ 2015-06-10 14:32 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      13427
Logged by:          Dmitri Bourlatchkov
Email address:      Dmitri.Bourlatchkov@software.dell.com
PostgreSQL version: 9.4.3
Operating system:   Windows Server 2008 (Korean)
Description:        

0. Log in as a local Administrator into a Korean version of the Windows
Server 2008
1. Install PostgreSQL 9.4.3 using the Windows .exe installer from
EnterpriseDB
2. Open cmd.exe shell
3. cd to potgresql/bin directory
4. Run postgresql.exe (no args)
5. Observe the following error message:

----
FATAL:  XX000: cannot perform encoding conversion outside a transaction
LOCATION:  pg_do_encoding_conversion, src\backend\utils\mb\mbutils.c:360
----

A similar message shows up when using pg_ctl.exe to start PostgreSQL.

Trouble-shooting attempted:
1. Run set LC_CTYPE=C
2. Run postgresql.exe (no args)
3. The following expected error shows up:

----
Execution of PostgreSQL by a user with administrative permissions is not
permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromises.  See the documentation for
more information on how to properly start the server.
----

Note: PostgreSQL _is_ able to run as a Windows Service without any
environment modifications.

Note: If the LC_CTYPE=C env. variable is set, PosgreSQL can also be started
successfully via pg_ctl (under the Administrator user).

Thanks,

  Dmitri.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid
  2015-06-10 14:32 BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid Dmitri.Bourlatchkov@software.dell.com
@ 2015-08-05 03:32 ` Noah Misch <noah@leadboat.com>
  2015-08-12 05:57   ` Re: BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid Noah Misch <noah@leadboat.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Noah Misch @ 2015-08-05 03:32 UTC (permalink / raw)
  To: Dmitri.Bourlatchkov@software.dell.com; +Cc: pgsql-bugs; tgl@sss.pgh.pa.us

On Wed, Jun 10, 2015 at 02:32:35PM +0000, Dmitri.Bourlatchkov@software.dell.com wrote:
> PostgreSQL version: 9.4.3
> Operating system:   Windows Server 2008 (Korean)

> 0. Log in as a local Administrator into a Korean version of the Windows
> Server 2008
> 1. Install PostgreSQL 9.4.3 using the Windows .exe installer from
> EnterpriseDB
> 2. Open cmd.exe shell
> 3. cd to potgresql/bin directory
> 4. Run postgresql.exe (no args)
> 5. Observe the following error message:
> 
> ----
> FATAL:  XX000: cannot perform encoding conversion outside a transaction
> LOCATION:  pg_do_encoding_conversion, src\backend\utils\mb\mbutils.c:360
> ----
> 
> A similar message shows up when using pg_ctl.exe to start PostgreSQL.

Thanks for this report.  One can reproduce this without Korean-specific OS
configuration by setting LC_CTYPE=Korean in the environment and then, as you
say, running postgres without arguments.  Stack trace:

	postgres.exe!errfinish(int dummy, ...) Line 412
	postgres.exe!elog_finish(int elevel, const char * fmt, ...) Line 1376
	postgres.exe!pg_do_encoding_conversion(unsigned char * src, int len, int src_encoding, int dest_encoding) Line 362
	postgres.exe!pgwin32_message_to_UTF16(const char * str, int len, int * utf16len) Line 1081
	postgres.exe!write_console(const char * line, int len) Line 2111
	postgres.exe!write_stderr(const char * fmt, ...) Line 3592
	postgres.exe!SelectConfigFiles(const char * userDoption, const char * progname) Line 4297
	postgres.exe!PostmasterMain(int argc, char * * argv) Line 802

Commit 49c817e is the proximate cause.  On my Windows Server 2008 system,
Korean is the only locale affected.  It's affected because pg_enc2name_tbl
lacks a UHC <-> CP949 mapping.  I'll double check, but adding that mapping
should fix this particular test case.

That leaves other ways of reaching this error.  I think e.g. an LC_CTYPE=C,
ENCODING=LATIN9 database will still take this path.  Any EmitErrorReport() can
run pgwin32_message_to_UTF16(), and those have plenty of ways to run outside a
transaction.  I am inclined to restore the 9.3 and earlier semantics by having
pgwin32_message_to_UTF16() proceed, when outside a transaction, as though the
string is already UTF8.  A robust fix would be to cache enough information
about the message encoding to convert outside a transaction, exactly the way
we protect database<->client encoding conversions.  That feels more like a
master-only change, though it's a borderline case.

> Trouble-shooting attempted:
> 1. Run set LC_CTYPE=C
> 2. Run postgresql.exe (no args)
> 3. The following expected error shows up:
> 
> ----
> Execution of PostgreSQL by a user with administrative permissions is not
> permitted.
> The server must be started under an unprivileged user ID to prevent
> possible system security compromises.  See the documentation for
> more information on how to properly start the server.
> ----
> 
> Note: PostgreSQL _is_ able to run as a Windows Service without any
> environment modifications.
> 
> Note: If the LC_CTYPE=C env. variable is set, PosgreSQL can also be started
> successfully via pg_ctl (under the Administrator user).

That looks normal.  pg_ctl has special code in CreateRestrictedProcess() to
drop administrative privileges.  To run raw postgres without pg_ctl, use an
unprivileged account or drop privileges similarly in your own wrapper.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid
  2015-06-10 14:32 BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid Dmitri.Bourlatchkov@software.dell.com
  2015-08-05 03:32 ` Re: BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid Noah Misch <noah@leadboat.com>
@ 2015-08-12 05:57   ` Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Noah Misch @ 2015-08-12 05:57 UTC (permalink / raw)
  To: Dmitri.Bourlatchkov@software.dell.com; +Cc: pgsql-bugs; tgl@sss.pgh.pa.us

On Tue, Aug 04, 2015 at 11:32:11PM -0400, Noah Misch wrote:
> On Wed, Jun 10, 2015 at 02:32:35PM +0000, Dmitri.Bourlatchkov@software.dell.com wrote:
> > 4. Run postgresql.exe (no args)
> > 5. Observe the following error message:
> > 
> > ----
> > FATAL:  XX000: cannot perform encoding conversion outside a transaction
> > LOCATION:  pg_do_encoding_conversion, src\backend\utils\mb\mbutils.c:360
> > ----

> Commit 49c817e is the proximate cause.  On my Windows Server 2008 system,
> Korean is the only locale affected.  It's affected because pg_enc2name_tbl
> lacks a UHC <-> CP949 mapping.  I'll double check, but adding that mapping
> should fix this particular test case.
> 
> That leaves other ways of reaching this error.  I think e.g. an LC_CTYPE=C,
> ENCODING=LATIN9 database will still take this path.

LATIN9 does not, but LATIN8 does.  Plain 'make check' fails early in Korean
locales, and 'make check EXTRA_REGRESS_OPTS="--encoding=LATIN8 --no-locale"'
fails in any OS locale.

> Any EmitErrorReport() can
> run pgwin32_message_to_UTF16(), and those have plenty of ways to run outside a
> transaction.  I am inclined to restore the 9.3 and earlier semantics by having
> pgwin32_message_to_UTF16() proceed, when outside a transaction, as though the
> string is already UTF8.

I am attaching the two patches I plan to use.  Either one by itself fixes the
symptom you observed.

> A robust fix would be to cache enough information
> about the message encoding to convert outside a transaction, exactly the way
> we protect database<->client encoding conversions.  That feels more like a
> master-only change, though it's a borderline case.

I propose to add this to https://wiki.postgresql.org/wiki/Todo:

 * Multi-Language Support
 ** Windows: Cache MessageEncoding conversion for use outside transactions

Thanks,
nm

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments: download all (2 files, .tar.gz)

to_UTF16-outside-xact-v1.patch (text/plain, 2.1K) download commit 48d9766 Author: Noah Misch <noah@leadboat.com> AuthorDate: Wed Aug 12 01:42:53 2015 -0400 Commit: Noah Misch <noah@leadboat.com> CommitDate: Wed Aug 12 01:42:53 2015 -0400 Restore old pgwin32_message_to_UTF16() behavior outside transactions. Commit 49c817eab78c6f0ce8c3bf46766b73d6cf3190b7 replaced with a hard error the dubious pg_do_encoding_conversion() behavior when outside a transaction. Reintroduce the historic soft failure locally within pgwin32_message_to_UTF16(). This fixes errors when writing messages in less-common encodings to the Windows event log or console. Back-patch to 9.4, where the aforementioned commit first appeared. Per bug #13427 from Dmitri Bourlatchkov. diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index 1e9a004..2a8271a 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -1063,7 +1063,8 @@ pgwin32_message_to_UTF16(const char *str, int len, int *utf16len) /* * Use MultiByteToWideChar directly if there is a corresponding codepage, - * or double conversion through UTF8 if not. + * or double conversion through UTF8 if not. Double conversion is needed, + * for example, in an ENCODING=LATIN8, LC_CTYPE=C database. */ if (codepage != 0) { @@ -1075,12 +1076,21 @@ pgwin32_message_to_UTF16(const char *str, int len, int *utf16len) { char *utf8; - utf8 = (char *) pg_do_encoding_conversion((unsigned char *) str, - len, - GetMessageEncoding(), - PG_UTF8); - if (utf8 != str) - len = strlen(utf8); + /* + * XXX pg_do_encoding_conversion() requires a transaction. In the + * absence of one, hope for the input to be valid UTF8. + */ + if (IsTransactionState()) + { + utf8 = (char *) pg_do_encoding_conversion((unsigned char *) str, + len, + GetMessageEncoding(), + PG_UTF8); + if (utf8 != str) + len = strlen(utf8); + } + else + utf8 = (char *) str; utf16 = (WCHAR *) palloc(sizeof(WCHAR) * (len + 1)); dstlen = MultiByteToWideChar(CP_UTF8, 0, utf8, len, utf16, len);
uhc-v1.patch (text/plain, 1.2K) download commit f20025b (HEAD) Author: Noah Misch <noah@leadboat.com> AuthorDate: Wed Aug 12 01:43:17 2015 -0400 Commit: Noah Misch <noah@leadboat.com> CommitDate: Wed Aug 12 01:43:17 2015 -0400 Encoding PG_UHC is code page 949. This fixes presentation of non-ASCII messages to the Windows event log and console in rare cases involving Korean locale. Processes like the postmaster and checkpointer, but not processes attached to databases, were affected. Back-patch to 9.4, where MessageEncoding was introduced. The problem exists in all supported versions, but this change has no effect in the absence of the code recognizing PG_UHC MessageEncoding. Noticed while investigating bug #13427 from Dmitri Bourlatchkov. diff --git a/src/backend/utils/mb/encnames.c b/src/backend/utils/mb/encnames.c index 94334c4..11099b8 100644 --- a/src/backend/utils/mb/encnames.c +++ b/src/backend/utils/mb/encnames.c @@ -344,7 +344,7 @@ const pg_enc2name pg_enc2name_tbl[] = DEF_ENC2NAME(SJIS, 932), DEF_ENC2NAME(BIG5, 950), DEF_ENC2NAME(GBK, 936), - DEF_ENC2NAME(UHC, 0), + DEF_ENC2NAME(UHC, 949), DEF_ENC2NAME(GB18030, 54936), DEF_ENC2NAME(JOHAB, 0), DEF_ENC2NAME(SHIFT_JIS_2004, 932)
^ permalink raw reply [nested|flat] 3+ messages in thread


end of thread, other threads:[~2015-08-12 05:57 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-06-10 14:32 BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid Dmitri.Bourlatchkov@software.dell.com
2015-08-05 03:32 ` Noah Misch <noah@leadboat.com>
2015-08-12 05:57   ` Noah Misch <noah@leadboat.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox