Commit 5fdefbc7 authored by Marc G. Fournier's avatar Marc G. Fournier

From: t-ishii@sra.co.jp

As mentioned around line 1153 in backend/commands/copy.c, the method
of array checking is not perfect.

test=> create table t1 (i text);
test=> insert into t1 values('{\\.}');
INSERT 2645600 1
test=> select * from t1;
i
-----
{\\.}
(2 rows)
test=> copy t1 to '/tmp/aaa';
test=> copy t1 from '/tmp/aaa';
ERROR:  CopyReadAttribute - end of record marker corrupted

Copy cannot read data produced by itself!
parent 7a7770e6
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.46 1998/06/15 19:28:13 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.47 1998/06/19 11:40:46 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -61,7 +61,7 @@ static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline ...@@ -61,7 +61,7 @@ static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline
static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim); static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim);
#endif #endif
static void CopyAttributeOut(FILE *fp, char *string, char *delim); static void CopyAttributeOut(FILE *fp, char *string, char *delim, int is_array);
static int CountTuples(Relation relation); static int CountTuples(Relation relation);
extern FILE *Pfout, extern FILE *Pfout,
...@@ -277,7 +277,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim) ...@@ -277,7 +277,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
{ {
string = (char *) (*fmgr_faddr(&out_functions[i])) string = (char *) (*fmgr_faddr(&out_functions[i]))
(value, elements[i], typmod[i]); (value, elements[i], typmod[i]);
CopyAttributeOut(fp, string, delim); CopyAttributeOut(fp, string, delim, attr[i]->attnelems);
pfree(string); pfree(string);
} }
else else
...@@ -554,7 +554,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim) ...@@ -554,7 +554,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
{ {
loaded_oid = oidin(string); loaded_oid = oidin(string);
if (loaded_oid < BootstrapObjectIdData) if (loaded_oid < BootstrapObjectIdData)
elog(ERROR, "COPY TEXT: Invalid Oid"); elog(ERROR, "COPY TEXT: Invalid Oid. line: %d", lineno);
} }
} }
for (i = 0; i < attr_count && !done; i++) for (i = 0; i < attr_count && !done; i++)
...@@ -603,7 +603,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim) ...@@ -603,7 +603,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
{ {
fread(&loaded_oid, sizeof(int32), 1, fp); fread(&loaded_oid, sizeof(int32), 1, fp);
if (loaded_oid < BootstrapObjectIdData) if (loaded_oid < BootstrapObjectIdData)
elog(ERROR, "COPY BINARY: Invalid Oid"); elog(ERROR, "COPY BINARY: Invalid Oid line: %d", lineno);
} }
fread(&null_ct, sizeof(int32), 1, fp); fread(&null_ct, sizeof(int32), 1, fp);
if (null_ct > 0) if (null_ct > 0)
...@@ -642,7 +642,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim) ...@@ -642,7 +642,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
ptr += sizeof(int32); ptr += sizeof(int32);
break; break;
default: default:
elog(ERROR, "COPY BINARY: impossible size!"); elog(ERROR, "COPY BINARY: impossible size! line: %d", lineno);
break; break;
} }
} }
...@@ -1099,7 +1099,7 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim) ...@@ -1099,7 +1099,7 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
case '.': case '.':
c = getc(fp); c = getc(fp);
if (c != '\n') if (c != '\n')
elog(ERROR, "CopyReadAttribute - end of record marker corrupted"); elog(ERROR, "CopyReadAttribute - end of record marker corrupted. line: %d", lineno);
return (NULL); return (NULL);
break; break;
} }
...@@ -1115,22 +1115,16 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim) ...@@ -1115,22 +1115,16 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
if (!done) if (!done)
attribute[i++] = c; attribute[i++] = c;
if (i == EXT_ATTLEN - 1) if (i == EXT_ATTLEN - 1)
elog(ERROR, "CopyReadAttribute - attribute length too long"); elog(ERROR, "CopyReadAttribute - attribute length too long. line: %d", lineno);
} }
attribute[i] = '\0'; attribute[i] = '\0';
return (&attribute[0]); return (&attribute[0]);
} }
static void static void
CopyAttributeOut(FILE *fp, char *string, char *delim) CopyAttributeOut(FILE *fp, char *string, char *delim, int is_array)
{ {
char c; char c;
int is_array = false;
int len = strlen(string);
/* XXX - This is a kludge, we should check the data type */
if (len && (string[0] == '{') && (string[len - 1] == '}'))
is_array = true;
for (; (c = *string) != '\0'; string++) for (; (c = *string) != '\0'; string++)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment