Re: pg_read_file() with virtual files returns empty string - Mailing list pgsql-hackers

From Tom Lane
Subject Re: pg_read_file() with virtual files returns empty string
Date
Msg-id 148675.1593287024@sss.pgh.pa.us
Whole thread Raw
In response to pg_read_file() with virtual files returns empty string  (Joe Conway <mail@joeconway.com>)
Responses Re: pg_read_file() with virtual files returns empty string  (Joe Conway <mail@joeconway.com>)
List pgsql-hackers
Joe Conway <mail@joeconway.com> writes:
> The attached patch fixes this for me. I think it ought to be backpatched through
> pg11.

> Comments?

1. Doesn't seem to be accounting for the possibility of an error in fread().

2. Don't we want to remove the stat() call altogether, if we're not
going to believe its length?

3. This bit might need to cast the RHS to int64:
    if (bytes_to_read > (MaxAllocSize - VARHDRSZ))
otherwise it might be treated as an unsigned comparison.
Or you could check for bytes_to_read < 0 separately.

4. appendStringInfoString seems like quite the wrong thing to use
when the input is binary data.

5. Don't like the comment.  Whether the file is virtual or not isn't
very relevant here.

6. If the file size exceeds 1GB, I fear we'll get some rather opaque
failure from the stringinfo infrastructure.  It'd be better to
check for that here and give a file-too-large error.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Fwd: PostgreSQL: WolfSSL support
Next
From: Bruce Momjian
Date:
Subject: Re: pg_bsd_indent compiles bytecode