Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit00a9229

Browse files
committed
Fix SortTocFromFile() to cope with lines that are too long for its buffer.
The original coding supposed that a dump TOC file could never contain lineslonger than 1K. The folly of that was exposed by a recent report fromPer-Olov Esgard. We only really need to see the first dozen or two bytesof each line, since we're just trying to read off the numeric ID at thestart of the line; so there's no need for a particularly huge buffer.What there is a need for is logic to not process continuation bufferloads.Back-patch to all supported branches, since it's always been like this.
1 parent93acf04 commit00a9229

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -789,11 +789,8 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
789789
{
790790
ArchiveHandle*AH= (ArchiveHandle*)AHX;
791791
FILE*fh;
792-
charbuf[1024];
793-
char*cmnt;
794-
char*endptr;
795-
DumpIdid;
796-
TocEntry*te;
792+
charbuf[100];
793+
boolincomplete_line;
797794
TocEntry*tePrev;
798795

799796
/* Allocate space for the 'wanted' array, and init it */
@@ -809,8 +806,30 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
809806
die_horribly(AH,modulename,"could not open TOC file: %s\n",
810807
strerror(errno));
811808

809+
incomplete_line= false;
812810
while (fgets(buf,sizeof(buf),fh)!=NULL)
813811
{
812+
boolprev_incomplete_line=incomplete_line;
813+
intbuflen;
814+
char*cmnt;
815+
char*endptr;
816+
DumpIdid;
817+
TocEntry*te;
818+
819+
/*
820+
* Some lines in the file might be longer than sizeof(buf). This is
821+
* no problem, since we only care about the leading numeric ID which
822+
* can be at most a few characters; but we have to skip continuation
823+
* bufferloads when processing a long line.
824+
*/
825+
buflen=strlen(buf);
826+
if (buflen>0&&buf[buflen-1]=='\n')
827+
incomplete_line= false;
828+
else
829+
incomplete_line= true;
830+
if (prev_incomplete_line)
831+
continue;
832+
814833
/* Truncate line at comment, if any */
815834
cmnt=strchr(buf,';');
816835
if (cmnt!=NULL)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp