dbTalk Databases Forums  

[BUGS] BUG #2221: Bad delimiters allowed in COPY ... TO

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #2221: Bad delimiters allowed in COPY ... TO in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
David Fetter
 
Posts: n/a

Default [BUGS] BUG #2221: Bad delimiters allowed in COPY ... TO - 01-29-2006 , 03:50 PM







The following bug has been logged online:

Bug reference: 2221
Logged by: David Fetter
Email address: david (AT) fetter (DOT) org
PostgreSQL version: all
Operating system: all
Description: Bad delimiters allowed in COPY ... TO
Details:

This came up while I was testing my pg_dump "specify DELIMITER AS and/or
NULL AS" patch.

Below is a repro using newline. A similar problem happens when you specify
the delimiter as a backslash. Should COPY simply not allow these
delimiters? What about carriage return? Just in general, what bytes other
than null ought COPY to reject out of hand?

Also, what regression tests do we want to put in in order to ensure that
COPY ... TO generates output that COPY ... FROM can understand?

CREATE TABLE pqxxevents (
"year" integer,
event text
);

COPY pqxxevents ("year", event) FROM stdin DELIMITER AS '^M';
2010^MOdyssey Two
2038^Mtime_t overflow
1971^Mjtv
1981^MC:\\>
1997^MAsian crisis
1999^M\N
1978^Mbloody\t\tcold
1989^MOde an die Freiheit
2001^MNew millennium
2001^M'911' WTC attack
2001^MA Space Odyssey
2002^Mlibpqxx
3001^MFinal Odyssey
\.

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly

Reply With Quote
  #2  
Old   
David Fetter
 
Posts: n/a

Default Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ... TO - 01-29-2006 , 06:42 PM






--61jdw2sOBCFtR2d/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sun, Jan 29, 2006 at 09:50:08PM +0000, David Fetter wrote:
Quote:
The following bug has been logged online:

Bug reference: 2221
Logged by: David Fetter
Email address: david (AT) fetter (DOT) org
PostgreSQL version: all
Operating system: all
Description: Bad delimiters allowed in COPY ... TO
Details:

This came up while I was testing my pg_dump "specify DELIMITER AS and/or
NULL AS" patch.
Folks,

Please pardon the self-followup. I believe that this patch fixes the
problem in COPY.

Cheers,
D
--
David Fetter david (AT) fetter (DOT) org http://fetter.org/
phone: +1 415 235 3778

Remember to vote!

--61jdw2sOBCFtR2d/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="forbid_badchars_copy.diff"

Index: src/backend/commands/copy.c
================================================== =================
RCS file: /projects/cvsroot/pgsql/src/backend/commands/copy.c,v
retrieving revision 1.257
diff -c -r1.257 copy.c
*** src/backend/commands/copy.c 28 Dec 2005 03:25:32 -0000 1.257
--- src/backend/commands/copy.c 30 Jan 2006 00:39:28 -0000
***************
*** 51,56 ****
--- 51,57 ----

#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
#define OCTVALUE(c) ((c) - '0')
+ #define BADCHARS "\r\n\\"

/*
* Represents the different source/dest cases we need to worry about at
***************
*** 856,861 ****
--- 857,867 ----
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("COPY delimiter must be a single character")));

+ /* Disallow the forbidden_delimiter strings from src/include/commands/copy.h */
+ if (strcspn(cstate->delim, BADCHARS) != 1)
+ elog(ERROR, "COPY delimiter cannot be %#02x",
+ *cstate->delim);
+
/* Check header */
if (!cstate->csv_mode && cstate->header_line)
ereport(ERROR,

--61jdw2sOBCFtR2d/
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

--61jdw2sOBCFtR2d/--


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.