pg.ddx.io pgsql-bugs@postgresql.org mailing list archivehelp / color / mirror / Atom feed
possible bug in COPY ... FROM ... NULL '\0' 2+ messages / 2 participants [nested] [flat]
* possible bug in COPY ... FROM ... NULL '\0' @ 2012-03-25 23:55 Jeff Davis <pgsql@j-davis.com> 2012-03-26 00:36 ` Re: possible bug in COPY ... FROM ... NULL '\0' Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: Jeff Davis @ 2012-03-25 23:55 UTC (permalink / raw) To: pgsql-bugs The documentation says: "The specified null string is sent by COPY TO without adding any backslashes; conversely, COPY FROM matches the input against the null string before removing backslashes." -- http://www.postgresql.org/docs/devel/static/sql-copy.html Those seem inconsistent with the following behavior: postgres=# copy foo to '/tmp/a.copy' null '\0'; COPY 2 postgres=# copy foo from '/tmp/a.copy' null '\0'; ERROR: invalid byte sequence for encoding "UTF8": 0x00 CONTEXT: COPY foo, line 2: "\0" $ cat /tmp/a.copy 1 \0 COPY TO seems to follow the documentation, inserting the null string without modification into the output file. COPY FROM seems to de-escape the input before trying to match it against the null string, leading to the invalid byte sequence. standard_conforming_strings is on. Regards, Jeff Davis ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: possible bug in COPY ... FROM ... NULL '\0' 2012-03-25 23:55 possible bug in COPY ... FROM ... NULL '\0' Jeff Davis <pgsql@j-davis.com> @ 2012-03-26 00:36 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2012-03-26 00:36 UTC (permalink / raw) To: Jeff Davis <pgsql@j-davis.com>; +Cc: pgsql-bugs Jeff Davis <pgsql@j-davis.com> writes: > The documentation says: > "The specified null string is sent by COPY TO without adding any > backslashes; conversely, COPY FROM matches the input against the null > string before removing backslashes." > -- http://www.postgresql.org/docs/devel/static/sql-copy.html > Those seem inconsistent with the following behavior: > postgres=# copy foo to '/tmp/a.copy' null '\0'; > COPY 2 > postgres=# copy foo from '/tmp/a.copy' null '\0'; > ERROR: invalid byte sequence for encoding "UTF8": 0x00 > CONTEXT: COPY foo, line 2: "\0" > $ cat /tmp/a.copy > 1 > \0 > COPY TO seems to follow the documentation, inserting the null string > without modification into the output file. COPY FROM seems to de-escape > the input before trying to match it against the null string, leading to > the invalid byte sequence. This seems to have worked as per the documentation before 8.4. I guess it got broken in one of the efficiency-driven rewrites of the COPY logic. Specifically, the issue seems to be that CopyReadAttributesText tries to combine de-escaping with locating the end-of-field, so it does all the de-escaping --- and the ensuing encoding validity check --- before checking to see if the input matches the defined null string. I'm pretty sure that the original code first broke the line into fields, then checked the null marker, then did de-escaping. Fortunately, it seems pretty easy to fix: we just have to reverse the order of the null-marker check and the pg_verifymbstr call. However, this is dependent on the parsing loop never having a reason to throw error, which at the very least is something that needs a comment. regards, tom lane ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2012-03-26 00:36 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2012-03-25 23:55 possible bug in COPY ... FROM ... NULL '\0' Jeff Davis <pgsql@j-davis.com> 2012-03-26 00:36 ` Tom Lane <tgl@sss.pgh.pa.us>
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