0x1A in control file on Windows

From: ITAGAKI Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org, pgsql-bugs(at)postgresql(dot)org
Subject: 0x1A in control file on Windows
Date: 2008-09-18 02:32:31
Message-ID: 20080918112547.80C7.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

I found a bug that pg_controldata ends with error if control files
contain 0x1A (Ctrl+Z) on Windows.

We probably need to add PG_BINARY when we open control files
because 0x1A is an end-of-file marker on Windows.
This fix needs to be applied in back versions (8.2, 8.3 and HEAD).

Index: src/bin/pg_controldata/pg_controldata.c
===================================================================
--- src/bin/pg_controldata/pg_controldata.c (head)
+++ src/bin/pg_controldata/pg_controldata.c (pg_control_0x1A)
@@ -107,7 +107,7 @@

snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);

- if ((fd = open(ControlFilePath, O_RDONLY, 0)) == -1)
+ if ((fd = open(ControlFilePath, O_RDONLY | PG_BINARY, 0)) == -1)
{
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
progname, ControlFilePath, strerror(errno));
Index: src/bin/pg_resetxlog/pg_resetxlog.c
===================================================================
--- src/bin/pg_resetxlog/pg_resetxlog.c (head)
+++ src/bin/pg_resetxlog/pg_resetxlog.c (pg_control_0x1A)
@@ -373,7 +373,7 @@
char *buffer;
pg_crc32 crc;

- if ((fd = open(XLOG_CONTROL_FILE, O_RDONLY, 0)) < 0)
+ if ((fd = open(XLOG_CONTROL_FILE, O_RDONLY | PG_BINARY, 0)) < 0)
{
/*
* If pg_control is not there at all, or we can't read it, the odds

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2008-09-18 04:48:34 Re: [HACKERS] 0x1A in control file on Windows
Previous Message Tom Lane 2008-09-17 17:46:55 Re: BUG #4421: convert_to() should be immutable

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhe He 2008-09-18 02:39:55 Where is Aggregation Attribute
Previous Message Decibel! 2008-09-18 02:00:32 Re: New FSM patch